Module: Syobocal::DB::Mapper
- Included in:
- ChGroupLookup::Mapper, ChLookup::Mapper, ProgLookup::Mapper, TitleLookup::Mapper
- Defined in:
- lib/syobocal/db.rb
Instance Method Summary collapse
Instance Method Details
#map(elm) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/syobocal/db.rb', line 4 def map(elm) result = {} elm.each_element{|child| set(result, to_snake(child.name).to_sym, child, @map[child.name]) } result end |
#set(hash, key, elm, type) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/syobocal/db.rb', line 16 def set(hash, key, elm, type) if elm val = nil if elm.text case type when :str val = elm.text when :int val = elm.text.to_i when :time val = Time.parse(elm.text) else raise "Undefined mapping for #{key}" if $SYOBOCAL_STRICT val = elm.text end end hash[key] = val end end |
#to_snake(name) ⇒ Object
12 13 14 |
# File 'lib/syobocal/db.rb', line 12 def to_snake(name) name.gsub(/([a-z])([A-Z])/){ $1 + '_' + $2 }.downcase end |