Top Level Namespace
Defined Under Namespace
Instance Method Summary collapse
-
#clean(string) ⇒ Object
remove spaces at the beginning of string remove extra spaces and special chars with a single space.
- #day(string) ⇒ Object
- #has_day(input) ⇒ Object
- #has_month(input) ⇒ Object
- #month(string) ⇒ Object
-
#reflow(string, chars) ⇒ Object
break a string into substrings of length chars breaking at spaces and newlines.
-
#year(string) ⇒ Object
Utility function for managing dates (2015-01-01) and partial dates (2015-05).
Instance Method Details
#clean(string) ⇒ Object
remove spaces at the beginning of string remove extra spaces and special chars with a single space
8 9 10 |
# File 'lib/resme/renderer/renderer.rb', line 8 def clean string string.gsub(/^[\t\n ]+/, "").gsub(/[\t\n ]+/, " ") end |
#day(string) ⇒ Object
50 51 52 |
# File 'lib/resme/renderer/renderer.rb', line 50 def day string string.to_s[8..9] end |
#has_day(input) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/resme/renderer/renderer.rb', line 62 def has_day input if input.class == Date true else input.size == 10 end end |
#has_month(input) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/resme/renderer/renderer.rb', line 54 def has_month input if input.class == Date true else input.size >= 7 end end |
#month(string) ⇒ Object
46 47 48 |
# File 'lib/resme/renderer/renderer.rb', line 46 def month string string.to_s[5..6] end |
#reflow(string, chars) ⇒ Object
break a string into substrings of length chars breaking at spaces and newlines
-
‘string` string to reflow
-
‘chars` number of characters to break the string at
-
returns an array of strings of length < chars (with exceptions for special cases)
special cases: if one line is longer than chars characters, then break at the first space after chars
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/resme/renderer/renderer.rb', line 23 def reflow string, chars if string.length < chars return [clean(string)] else chars.downto(0).each do |index| if string[index] == " " or string[index] == "\n" or string[index] == "\t" return [clean(string[0..index-1])] + reflow(string[index+1..-1], chars) end end chars.upto(string.length).each do |index| if string[index] == " " or string[index] == "\n" or string[index] == "\t" return [clean(string[0..index-1])] + reflow(string[index+1..-1], chars) end end return [clean(string)] end end |
#year(string) ⇒ Object
Utility function for managing dates (2015-01-01) and partial dates (2015-05)
42 43 44 |
# File 'lib/resme/renderer/renderer.rb', line 42 def year string string.to_s[0..3] end |