Class: Terrafying::Ref

Inherits:
Object
  • Object
show all
Defined in:
lib/terrafying/generator.rb

Direct Known Subclasses

AttributeRef, FnRef, IndexRef, RootRef

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



53
54
55
# File 'lib/terrafying/generator.rb', line 53

def <=>(other)
  self.to_s <=> other.to_s
end

#==(other) ⇒ Object



57
58
59
# File 'lib/terrafying/generator.rb', line 57

def ==(other)
  self.to_s == other.to_s
end

#[](key) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/terrafying/generator.rb', line 61

def [](key)
  if key.is_a? Numeric
    IndexRef.new(ref: self, idx: key)
  else
    AttributeRef.new(ref: self, key: key)
  end
end

#[]=(k, v) ⇒ Object



69
70
71
# File 'lib/terrafying/generator.rb', line 69

def []=(k, v)
  raise "You can't set a value this way"
end

#downcaseObject



21
22
23
# File 'lib/terrafying/generator.rb', line 21

def downcase
  fn_call("lower")
end

#fn_call(fn, *args) ⇒ Object



14
15
16
17
18
19
# File 'lib/terrafying/generator.rb', line 14

def fn_call(fn, *args)
  if args.length == 0
    args = [ARG_PLACEHOLDER]
  end
  FnRef.new(fn: fn, args: args, ref: self)
end

#realiseObject



41
42
43
# File 'lib/terrafying/generator.rb', line 41

def realise
  ""
end

#slice(idx, length = 0) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/terrafying/generator.rb', line 33

def slice(idx, length=0)
  if length != 0
    fn_call("slice", ARG_PLACEHOLDER, idx, idx+length)
  else
    fn_call("element", ARG_PLACEHOLDER, idx)
  end
end

#split(separator) ⇒ Object



29
30
31
# File 'lib/terrafying/generator.rb', line 29

def split(separator)
  fn_call("split", separator, ARG_PLACEHOLDER)
end

#stripObject



25
26
27
# File 'lib/terrafying/generator.rb', line 25

def strip
  fn_call("trimspace")
end

#to_sObject



45
46
47
# File 'lib/terrafying/generator.rb', line 45

def to_s
  "${#{realise}}"
end

#to_strObject



49
50
51
# File 'lib/terrafying/generator.rb', line 49

def to_str
  self.to_s
end