Module: Oat::Helpers

Included in:
Document
Defined in:
lib/oat/helpers.rb

Instance Method Summary collapse

Instance Method Details

#capture_the(prop, reg, offset = 0) ⇒ Object


21
22
23
24
25
# File 'lib/oat/helpers.rb', line 21

def capture_the(prop, reg, offset = 0)
  matches = @data.match(reg, offset)
  @scrapes[prop] = matches
  set_prop(prop, matches.nil? ? '' : matches[1])  #usually irrelevant, manually call set_prop after capture_the
end

#format_heisei_date(format, date) ⇒ Object


11
12
13
14
15
16
17
18
19
# File 'lib/oat/helpers.rb', line 11

def format_heisei_date(format, date)
  #date is MatchData object with three captures, the first being Heisei year
  #convert from 全角文字 to normal ascii 
  return '' if date.nil?
  y = (NKF.nkf('-m0Z1 -w', date[1]).to_i + 1988).to_s
  m = (NKF.nkf('-m0Z1 -w', date[2]).to_i).to_s
  d = (NKF.nkf('-m0Z1 -w', date[3]).to_i).to_s
  sprintf(format, y, m, d)
end

#set_prop(prop, value) ⇒ Object

the @props hash is passed to docx_templater gem


28
29
30
# File 'lib/oat/helpers.rb', line 28

def set_prop(prop, value)
  @props[prop] = value
end

#squish!(t) ⇒ Object


5
6
7
8
9
# File 'lib/oat/helpers.rb', line 5

def squish!(t)
  t.gsub!(/\A[[:space:]]+/, '')
  t.gsub!(/[[:space:]]+\z/, '')
  t.gsub!(/[[:space:]]+/, ' ')
end