Class: Erector::Dependency

Inherits:
Object
  • Object
show all
Defined in:
lib/erector/dependency.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, text, options = {}) ⇒ Dependency

Returns a new instance of Dependency.



5
6
7
8
9
# File 'lib/erector/dependency.rb', line 5

def initialize(type, text, options = {})
  text = text.read if text.is_a? IO
  text = self.class.interpolate(text) if options[:interpolate] # todo: test
  @type, @text, @options = type, text, options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/erector/dependency.rb', line 3

def options
  @options
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/erector/dependency.rb', line 3

def text
  @text
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/erector/dependency.rb', line 3

def type
  @type
end

Class Method Details

.interpolate(s) ⇒ Object



11
12
13
# File 'lib/erector/dependency.rb', line 11

def self.interpolate(s)
  eval("<<INTERPOLATE\n" + s + "\nINTERPOLATE").chomp
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
18
19
# File 'lib/erector/dependency.rb', line 15

def ==(other)
  (self.type == other.type and
   self.text == other.text and
   self.options == other.options) ? true : false
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/erector/dependency.rb', line 21

def eql?(other)
  self == other
end

#hashObject



25
26
27
28
29
# File 'lib/erector/dependency.rb', line 25

def hash
  # this is a fairly inefficient hash function but it does the trick for
  # now
  "#{type}#{text}#{options}".hash
end