Class: Analects::ChiseIdsLoader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/analects/chise_ids_loader.rb

Defined Under Namespace

Classes: MultiFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pathname, library, only_unicode = true) ⇒ ChiseIdsLoader

Returns a new instance of ChiseIdsLoader.



17
18
19
20
# File 'lib/analects/chise_ids_loader.rb', line 17

def initialize(pathname, library, only_unicode = true)
  @contents = MultiFile.new(pathname.children.select{|ch| ch.to_s =~ /IDS-.*\.txt/})
  @only_unicode = only_unicode
end

Instance Attribute Details

#only_unicodeObject

Returns the value of attribute only_unicode.



5
6
7
# File 'lib/analects/chise_ids_loader.rb', line 5

def only_unicode
  @only_unicode
end

Instance Method Details

#each(&blk) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/analects/chise_ids_loader.rb', line 26

def each(&blk)
  return to_enum(__method__) unless block_given?
  @entries ||= @contents.each_line
    .reject {|line| line !~ /\t/ || (only_unicode && line !~ /^U/) }
    .map    {|line| line.strip.split("\t")[0..2] }
  @entries.each(&blk)
end

#field_namesObject



22
23
24
# File 'lib/analects/chise_ids_loader.rb', line 22

def field_names
  [:name, :representation, :ids]
end