Class: PSD::EngineData::Instruction

Inherits:
Object
  • Object
show all
Defined in:
lib/psd/enginedata/instruction.rb,
lib/psd/enginedata/instructions/noop.rb,
lib/psd/enginedata/instructions/number.rb,
lib/psd/enginedata/instructions/string.rb,
lib/psd/enginedata/instructions/boolean.rb,
lib/psd/enginedata/instructions/hash_end.rb,
lib/psd/enginedata/instructions/property.rb,
lib/psd/enginedata/instructions/hash_start.rb,
lib/psd/enginedata/instructions/single_line_array.rb,
lib/psd/enginedata/instructions/property_with_data.rb,
lib/psd/enginedata/instructions/number_with_decimal.rb,
lib/psd/enginedata/instructions/multi_line_array_end.rb,
lib/psd/enginedata/instructions/multi_line_array_start.rb

Overview

A single instruction as defined by the EngineData spec.

Defined Under Namespace

Classes: Boolean, HashEnd, HashStart, MultiLineArrayEnd, MultiLineArrayStart, Noop, Number, NumberWithDecimal, Property, PropertyWithData, SingleLineArray, String

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, text) ⇒ Instruction

Stores a reference to the EngineData document and the current String being parsed.



20
21
22
23
# File 'lib/psd/enginedata/instruction.rb', line 20

def initialize(document, text)
  @document = document
  @text = text
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/psd/enginedata/instruction.rb', line 34

def method_missing(method, *args, &block)
  if @document.respond_to?(method)
    return @document.send(method, *args)
  end

  super
end

Class Method Details

.match(text) ⇒ Object

Checks to see if the given text is a match for this token.



10
11
12
13
14
15
16
# File 'lib/psd/enginedata/instruction.rb', line 10

def self.match(text)
  begin
    token.match(text)
  rescue Encoding::CompatibilityError
    nil
  end
end

.tokenObject

The regex for the token, defaulted to nil. Override this.



7
# File 'lib/psd/enginedata/instruction.rb', line 7

def self.token; end

Instance Method Details

#execute!Object

Once matched, we execute the instruction and apply the changes to the parsed data.



32
# File 'lib/psd/enginedata/instruction.rb', line 32

def execute!; end

#matchObject

Returns the regex match to the current string.



26
27
28
# File 'lib/psd/enginedata/instruction.rb', line 26

def match
  self.class.match @text
end