Class: ValuesReaderV2

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/textutils/reader/values_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, more_attribs = {}) ⇒ ValuesReaderV2

Returns a new instance of ValuesReaderV2.



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

def initialize( name, include_path, more_attribs={} )
  @name          = name
  @include_path  = include_path
  @more_attribs  = more_attribs
  
  # 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.



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

def include_path
  @include_path
end

#more_attribsObject (readonly)

Returns the value of attribute more_attribs.



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

def more_attribs
  @more_attribs
end

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'lib/textutils/reader/values_reader.rb', line 30

def name
  @name
end

#name_real_pathObject (readonly)

Returns the value of attribute name_real_path.



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

def name_real_path
  @name_real_path
end

Instance Method Details

#each_lineObject



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

def each_line
  path          = "#{include_path}/#{name_real_path}.txt"
  reader        = ValuesReader.new( path, more_attribs )

  logger.info "parsing data '#{name}' (#{path})..."

  reader.each_line do |attribs, values|
    yield( attribs, values )
  end

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