Class: Transform

Inherits:
Object
  • Object
show all
Defined in:
lib/pertinent_parser/transform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, property) ⇒ Transform

Returns a new instance of Transform.



4
5
6
# File 'lib/pertinent_parser/transform.rb', line 4

def initialize type, property
  @type, @property = type, property
end

Instance Attribute Details

#propertyObject

Returns the value of attribute property.



2
3
4
# File 'lib/pertinent_parser/transform.rb', line 2

def property
  @property
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/pertinent_parser/transform.rb', line 2

def type
  @type
end

Instance Method Details

#apply(s) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/pertinent_parser/transform.rb', line 16

def apply(s)
  if @type == :identity
    return s
  elsif @type == :replacement
    return @property
  elsif @type == :wrap
    return @property[0] + s + @property[1]
  end
end

#split(n) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/pertinent_parser/transform.rb', line 8

def split(n)
  if @type == :replacement
    return [Transform.new(:replacement, @property[0..n-1]), Transform.new(:replacement, @property[n..-1])]
  elsif @type == :wrap
    return [self, self.dup]
  end
end