Class: HashReaderV2

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/textutils/reader/hash_reader.rb

Overview

todo/fix: find a better name than HashReaderV2 (HashReaderPlus?) ??

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, include_path) ⇒ HashReaderV2

Returns a new instance of HashReaderV2.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/textutils/reader/hash_reader.rb', line 12

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_pathObject (readonly)

Returns the value of attribute include_path.



33
34
35
# File 'lib/textutils/reader/hash_reader.rb', line 33

def include_path
  @include_path
end

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/textutils/reader/hash_reader.rb', line 31

def name
  @name
end

#name_real_pathObject (readonly)

Returns the value of attribute name_real_path.



32
33
34
# File 'lib/textutils/reader/hash_reader.rb', line 32

def name_real_path
  @name_real_path
end

Instance Method Details

#eachObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/textutils/reader/hash_reader.rb', line 35

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

  ## fix: move Prop table to props gem - why? why not??
  WorldDb::Models::Prop.create_from_fixture!( name, path )
end

#each_typedObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/textutils/reader/hash_reader.rb', line 50

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

  ## fix: move Prop table to props gem - why? why not??
  WorldDb::Models::Prop.create_from_fixture!( name, path )
end