Skip to content

Commit

Permalink
add support for symbol type
Browse files Browse the repository at this point in the history
  • Loading branch information
softbrada committed Sep 1, 2017
1 parent dc5e77d commit 1272f92
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
17 changes: 8 additions & 9 deletions lib/kansen/mapper/note_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ module Kansen
module Mapper
module NoteParser

PARSERS =
{ 'string' => 'Null',
'integer' => 'Integer',
'float' => 'Float',
'constant' => 'Constant' }
PARSERS = {
'string' => 'Null',
'integer' => 'Integer',
'float' => 'Float',
'constant' => 'Constant',
'symbol' => 'Symbol'
}.freeze

def self.parse(type, note)
Kernel.
const_get('Kansen').
const_get('Parser').
const_get(PARSERS[type]).parse(note)
Kernel.const_get('Kansen').const_get('Parser').const_get(PARSERS[type]).parse(note)
rescue
raise Kansen::MissingParser
end
Expand Down
6 changes: 3 additions & 3 deletions lib/kansen/mapper/note_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module Kansen
module Mapper
module NoteType

TYPES = %w{
string integer float constant
}
TYPES = %w[
string integer float constant symbol
].freeze

def self.perform(type)
raise Kansen::WrongNoteType unless TYPES.include? type
Expand Down
1 change: 1 addition & 0 deletions lib/kansen/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
require 'kansen/parser/integer'
require 'kansen/parser/constant'
require 'kansen/parser/null'
require 'kansen/parser/symbol'
7 changes: 7 additions & 0 deletions lib/kansen/parser/symbol.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Kansen::Parser
class Symbol
def self.parse(note)
note.to_sym
end
end
end

0 comments on commit 1272f92

Please sign in to comment.