Top Level Namespace
Defined Under Namespace
Instance Method Summary collapse
-
#clean(string) ⇒ Object
remove spaces at the beginning of string replace extra spaces and special chars with a single space.
- #day(string) ⇒ Object
- #full_name(data) ⇒ Object
- #has_day(input) ⇒ Object
- #has_month(input) ⇒ Object
-
#itemize(entry, header = ["role", "who", "address"]) ⇒ Object
make an entry into an item of a list - first argument, entry, is a hash containing the symbols specified in header and the following fields: summary and then from, till, or date - second argument, header, is an array of symbols, whose values, comma-separated will generate the header line.
- #month(string) ⇒ Object
-
#period(entry) ⇒ Object
manage dates of an entry flexibly supporting the following formats:.
-
#propertify(item, indentation = "") ⇒ Object
generate a list of org-mode properties from item and exclude summary from the list.
-
#reflow_to_array(string, chars) ⇒ Object
break a string into substrings of length chars breaking at spaces and newlines.
- #reflow_to_string(string, chars, indentation = "") ⇒ Object
-
#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 replace 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
116 117 118 |
# File 'lib/resme/renderer/renderer.rb', line 116 def day string string.to_s[8..9] end |
#full_name(data) ⇒ Object
12 13 14 |
# File 'lib/resme/renderer/renderer.rb', line 12 def full_name data [data.basics["first_name"], data.basics["middle_name"], data.basics["last_name"]].join(" ") end |
#has_day(input) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/resme/renderer/renderer.rb', line 128 def has_day input if input.class == Date true else input.size == 10 end end |
#has_month(input) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/resme/renderer/renderer.rb', line 120 def has_month input if input.class == Date true else input.size >= 7 end end |
#itemize(entry, header = ["role", "who", "address"]) ⇒ Object
make an entry into an item of a list
-
first argument, entry, is a hash containing the symbols specified in header and the following fields: summary and then from, till, or date
-
second argument, header, is an array of symbols, whose values, comma-separated will generate the header line
The output is along the lines of:
-
value of key1, value of key2 period reflowed summary
87 88 89 90 91 92 93 |
# File 'lib/resme/renderer/renderer.rb', line 87 def itemize entry, header = ["role", "who", "address"] <<EOS - #{clean header.map { |x| entry[x] }.join(", ")} #{period entry} #{reflow_to_string entry["summary"], 72, " "} EOS end |
#month(string) ⇒ Object
112 113 114 |
# File 'lib/resme/renderer/renderer.rb', line 112 def month string string.to_s[5..6] end |
#period(entry) ⇒ Object
manage dates of an entry flexibly supporting the following formats:
-
from - till (with ‘from` or `till` possibly partial or empty)
-
date (possibly partial)
abstract dates at the year level, taking care of periods if from and till are in two different years
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/resme/renderer/renderer.rb', line 61 def period entry if entry["date"] then "#{year entry.date}" else from_year = entry["from"] ? year(entry.from.to_s) : nil till_year = entry["till"] ? year(entry.till.to_s) : nil if from_year and till_year and from_year == till_year then from_year else "#{from_year} -- #{till_year ? till_year : "today"}" end end end |
#propertify(item, indentation = "") ⇒ Object
generate a list of org-mode properties from item and exclude summary from the list
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/resme/renderer/renderer.rb', line 96 def propertify item, indentation="" output = ":PROPERTIES:\n" item.each do |k, v| if not ["summary", "details"].include? k output << ":#{k.upcase}: #{v}\n" end end output << ":END:" output.gsub!(/^/, indentation) end |
#reflow_to_array(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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/resme/renderer/renderer.rb', line 27 def reflow_to_array 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_to_array(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_to_array(string[index+1..-1], chars) end end return [clean(string)] end end |
#reflow_to_string(string, chars, indentation = "") ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/resme/renderer/renderer.rb', line 45 def reflow_to_string string, chars, indentation = "" array = reflow_to_array string, chars output = "" array.each do |line| output << indentation + line + "\n" end output end |
#year(string) ⇒ Object
Utility function for managing dates (2015-01-01) and partial dates (2015-05)
108 109 110 |
# File 'lib/resme/renderer/renderer.rb', line 108 def year string string.to_s[0..3] end |