Class: CoffeeTable::Key
- Inherits:
-
Object
show all
- Includes:
- Utility
- Defined in:
- lib/coffee_table/key.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utility
#method_missing, #underscore
Constructor Details
#initialize(name, block_key, options, *objects) ⇒ Key
Returns a new instance of Key.
14
15
16
17
18
19
|
# File 'lib/coffee_table/key.rb', line 14
def initialize(name, block_key, options, *objects)
@name = name
@block_key = block_key
@options = options
@elements = objects.flatten.map{|o| key_for_object(o)}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class CoffeeTable::Utility
Class Method Details
.decode_element(element) ⇒ Object
78
79
80
|
# File 'lib/coffee_table/key.rb', line 78
def self.decode_element(element)
element.to_s.gsub("|", "|").gsub("&", "&")
end
|
.parse(string) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/coffee_table/key.rb', line 7
def self.parse(string)
elements = string.split("|", -1).map{|e| decode_element(e) }
key = Key.new(elements[0], elements[1], Hash[elements.last.split("&").map{|kv| [kv.split("=")[0].to_sym, kv.split("=")[1]]}])
key.elements = elements[2..-2]
key
end
|
Instance Method Details
#<=>(o) ⇒ Object
56
57
58
|
# File 'lib/coffee_table/key.rb', line 56
def <=>(o)
self.to_s <=> o.to_s
end
|
#add_flag(options) ⇒ Object
41
42
43
|
# File 'lib/coffee_table/key.rb', line 41
def add_flag(options)
@options.merge!(options)
end
|
#code_hash ⇒ Object
33
34
35
|
# File 'lib/coffee_table/key.rb', line 33
def code_hash
@block_key
end
|
#elements ⇒ Object
48
49
50
|
# File 'lib/coffee_table/key.rb', line 48
def elements
@elements
end
|
#elements=(elements) ⇒ Object
52
53
54
|
# File 'lib/coffee_table/key.rb', line 52
def elements=(elements)
@elements = elements
end
|
#has_element?(element) ⇒ Boolean
21
22
23
|
# File 'lib/coffee_table/key.rb', line 21
def has_element?(element)
matches?(element.to_s)
end
|
#has_element_type?(element) ⇒ Boolean
25
26
27
|
# File 'lib/coffee_table/key.rb', line 25
def has_element_type?(element)
matches?(element.to_s + "[", :match => :start)
end
|
#name ⇒ Object
29
30
31
|
# File 'lib/coffee_table/key.rb', line 29
def name
@name
end
|
#options ⇒ Object
37
38
39
|
# File 'lib/coffee_table/key.rb', line 37
def options
@options
end
|
#remove_flag(key) ⇒ Object
44
45
46
|
# File 'lib/coffee_table/key.rb', line 44
def remove_flag(key)
@options.delete key
end
|
#to_s ⇒ Object
60
61
62
|
# File 'lib/coffee_table/key.rb', line 60
def to_s
[encode_element(@name), encode_element(@block_key), @elements.map{|e| encode_element(e) }, encode_element(@options.map{|k,v| "#{k}=#{v}"}.join("&"))].flatten.join("|")
end
|