Class: Format
- Inherits:
-
Object
- Object
- Format
- Defined in:
- lib/format.rb
Class Method Summary collapse
- .examples(option, hash) ⇒ Object
- .monthswap(string) ⇒ Object
- .special(x) ⇒ Object
- .syntax(syntax) ⇒ Object
Class Method Details
.examples(option, hash) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/format.rb', line 2 def self.examples(option, hash) return if hash[:examples].nil? hash[:examples] .then { |x| x.is_a?(String) ? [x] : x } .map { |e| (" " * 2) + e } .unshift("--#{option} examples:") .join("\n") end |
.monthswap(string) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/format.rb', line 16 def self.monthswap(string) string = string.downcase %w[ january february march april may june july august september october november december ].map { |m| [m, m[0..2]].map { |x| Regexp.new(x) } } .zip(1..) do |names, i| names.each { |n| string.gsub!(n, i.to_s) } end string end |
.special(x) ⇒ Object
30 31 32 |
# File 'lib/format.rb', line 30 def self.special(x) eval "\"#{x}\"" end |
.syntax(syntax) ⇒ Object
12 13 14 |
# File 'lib/format.rb', line 12 def self.syntax(syntax) [syntax].flatten.join("\n") end |