Class: DateFormats::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/date-formats/reader.rb

Overview

parse words

Class Method Summary collapse

Class Method Details

.parse(txt) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/date-formats/reader.rb', line 13

def self.parse( txt )
  lines = [] # array of lines (with words)

  txt.each_line do |line|
    line = line.strip

    next if line.empty?
    next if line.start_with?( '#' )   ## skip comments too

    ## strip inline (until end-of-line) comments too
    ##   e.g. Janvier  Janv  Jan  ## check janv in use??
    ##   =>   Janvier  Janv  Jan

    line = line.sub( /#.*/, '' ).strip
    ## pp line

    values = line.split( /[ \t]+/ )
    ## pp values

    ## todo/fix -- add check for duplicates
    lines << values
  end
  lines
end

.read(path) ⇒ Object

todo/check: rename to WordReader or something for easy (re)use - why? why not?



8
9
10
11
# File 'lib/date-formats/reader.rb', line 8

def self.read( path )   ## use - rename to read_file or from_file etc. - why? why not?
  txt = File.open( path, 'r:utf-8' ).read
  parse( txt )
end