Class: Waddup::CLI
- Inherits:
-
Object
- Object
- Waddup::CLI
- Defined in:
- lib/waddup/cli.rb
Constant Summary collapse
- KEYWORDS =
{ sources: %w[with], from: %w[from since], to: %w[to until uptil upto through] }
- KEYWORD_BOUNDARY =
"(?:\\s#{KEYWORDS.values.flatten.join('|\\s')}|\\Z)"
Class Attribute Summary collapse
-
.from ⇒ Object
Returns the value of attribute from.
-
.sources ⇒ Object
Returns the value of attribute sources.
-
.to ⇒ Object
Returns the value of attribute to.
Class Method Summary collapse
Class Attribute Details
.from ⇒ Object
Returns the value of attribute from.
24 25 26 |
# File 'lib/waddup/cli.rb', line 24 def from @from end |
.sources ⇒ Object
Returns the value of attribute sources.
24 25 26 |
# File 'lib/waddup/cli.rb', line 24 def sources @sources end |
.to ⇒ Object
Returns the value of attribute to.
24 25 26 |
# File 'lib/waddup/cli.rb', line 24 def to @to end |
Class Method Details
.parse!(arguments) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/waddup/cli.rb', line 26 def parse!(arguments) @arguments = arguments.join ' ' parse_keyword :sources do |match| sources = match[1] @sources = Waddup::Source.usable.select do |source| sources.include? source::ALIAS end end parse_keyword :from do |match| @from = Chronic.parse match[1], context: :past end parse_keyword :to do |match| @to = Chronic.parse match[1], context: :past end end |
.parse_keyword(keyword, &block) ⇒ Object
45 46 47 |
# File 'lib/waddup/cli.rb', line 45 def parse_keyword(keyword, &block) @arguments.match /(?:#{KEYWORDS[keyword].join('|')})\s(.+?)#{KEYWORD_BOUNDARY}/i, &block end |