Class: HashReaderV2
- Inherits:
-
Object
- Object
- HashReaderV2
- Includes:
- LogUtils::Logging
- Defined in:
- lib/textutils/reader/hash_reader_v2.rb
Overview
todo/fix: find a better name than HashReaderV2 (HashReaderPlus?) ??
Instance Attribute Summary collapse
-
#include_path ⇒ Object
readonly
Returns the value of attribute include_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#name_real_path ⇒ Object
readonly
Returns the value of attribute name_real_path.
Instance Method Summary collapse
- #each ⇒ Object
- #each_typed ⇒ Object
-
#initialize(name, include_path) ⇒ HashReaderV2
constructor
A new instance of HashReaderV2.
Constructor Details
#initialize(name, include_path) ⇒ HashReaderV2
Returns a new instance of HashReaderV2.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/textutils/reader/hash_reader_v2.rb', line 10 def initialize( name, include_path ) @name = name @include_path = include_path # map name to name_real_path # name might include !/ for virtual path (gets cut off) # e.g. at-austria!/w-wien/beers becomse w-wien/beers pos = @name.index( '!/') if pos.nil? @name_real_path = @name # not found; real path is the same as name else # cut off everything until !/ e.g. # at-austria!/w-wien/beers becomes # w-wien/beers @name_real_path = @name[ (pos+2)..-1 ] end end |
Instance Attribute Details
#include_path ⇒ Object (readonly)
Returns the value of attribute include_path.
31 32 33 |
# File 'lib/textutils/reader/hash_reader_v2.rb', line 31 def include_path @include_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/textutils/reader/hash_reader_v2.rb', line 29 def name @name end |
#name_real_path ⇒ Object (readonly)
Returns the value of attribute name_real_path.
30 31 32 |
# File 'lib/textutils/reader/hash_reader_v2.rb', line 30 def name_real_path @name_real_path end |
Instance Method Details
#each ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/textutils/reader/hash_reader_v2.rb', line 33 def each path = "#{include_path}/#{name_real_path}.yml" reader = HashReader.new( path ) logger.info "parsing data '#{name}' (#{path})..." reader.each do |key, value| yield( key, value ) end ConfDb::Model::Prop.create_from_fixture!( name, path ) end |
#each_typed ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/textutils/reader/hash_reader_v2.rb', line 47 def each_typed path = "#{include_path}/#{name_real_path}.yml" reader = HashReader.new( path ) logger.info "parsing data '#{name}' (#{path})..." reader.each_typed do |key, value| yield( key, value ) end ConfDb::Model::Prop.create_from_fixture!( name, path ) end |