Class: FileScheduler::AttributesParser::Parsing

Inherits:
Object
  • Object
show all
Defined in:
lib/file_scheduler/attributes_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Parsing

Returns a new instance of Parsing.



12
13
14
# File 'lib/file_scheduler/attributes_parser.rb', line 12

def initialize(string)
  @string = string
end

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



10
11
12
# File 'lib/file_scheduler/attributes_parser.rb', line 10

def string
  @string
end

Instance Method Details

#attributesObject



29
30
31
32
33
34
35
# File 'lib/file_scheduler/attributes_parser.rb', line 29

def attributes
  pairs.inject({}) do |attributes, pair|
    key, value = pair.split("=")
    attributes[key.strip.to_sym] = value.strip
    attributes
  end
end

#definitionObject



16
17
18
19
20
21
22
23
# File 'lib/file_scheduler/attributes_parser.rb', line 16

def definition
  # Matches {...}$ or {...}.ext$
  if string =~ /\{([^\}]+)\}($|\.[^.]+$)/
    $1
  else
    ""
  end
end

#pairsObject



25
26
27
# File 'lib/file_scheduler/attributes_parser.rb', line 25

def pairs
  definition.split(",")
end