Module: CsvHuman::DocHelper

Included in:
Doc
Defined in:
lib/csvhuman/doc/helper.rb

Constant Summary collapse

HASHTAG_LINE_RX =
/^
\s*
\#
(?<name>[a-z][a-z0-9]+)
\s*
$/x
ATTRIBUTE_LINE_RX =

note: attrib might be one letter only (e.g.) m,f, etc.

/^
\s*
\+
(?<name>[a-z][a-z0-9]*)
\s*
$/x
HEADING_LINE_RX =

e.g. 1.1. Places

2.1. Sex- and-age disaggregation (SADD) attributes
/^
\s*
(?<level1>[1-9])
  \.
(?<level2>[1-9])
  \.
  \s+
 (?<title>.+?)
  \s*
$/x
TYPE_RX =
/Every value must be a (?<type>[a-z]+)./
SINCE_HXL_RX =
/Since HXL (?<version>[1]\.[0-9])\.?/

Instance Method Summary collapse

Instance Method Details

#match_attribute(line) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/csvhuman/doc/helper.rb', line 33

def match_attribute( line )
   if (m=ATTRIBUTE_LINE_RX.match(line))
     puts "attrib >#{m[:name]}<"
     m
   else
     false
   end
end

#match_hashtag(line) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/csvhuman/doc/helper.rb', line 14

def match_hashtag( line )
   if (m=HASHTAG_LINE_RX.match(line))
     puts "hashtag >#{m[:name]}<"
     m
   else
     nil
   end
end

#match_heading(line) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/csvhuman/doc/helper.rb', line 59

def match_heading( line )
  if (m=HEADING_LINE_RX.match(line))
    puts "heading #{m[:level1]}.#{m[:level2]}. (#{m[:level2]}) >#{m[:title]}<"
    m
  else
    false
  end
end

#match_since_hxl(line) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/csvhuman/doc/helper.rb', line 83

def match_since_hxl( line )
  if (m=SINCE_HXL_RX.match(line))
    puts "version: >#{m[:version]}<"
    m
  else
    false
  end
end

#match_type(line) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/csvhuman/doc/helper.rb', line 71

def match_type( line )
  if (m=TYPE_RX.match(line))
    puts "type: >#{m[:type]}<"
    m
  else
    false
  end
end

#split_descr(line) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/csvhuman/doc/helper.rb', line 94

def split_descr( line )
  if( m=match_since_hxl( line ))
    version = m[:version]
    ## remove "Since HXL 1.0" from text
    text    = line.gsub( SINCE_HXL_RX, '' ).strip
  else
    version = '?'
    text = line
  end
  [text,version]
end