Class: Lolita::Builder::Custom
Instance Attribute Summary collapse
-
#build_attributes ⇒ Object
Returns the value of attribute build_attributes.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(element, attributes_as_hash) ⇒ Custom
constructor
A new instance of Custom.
- #name ⇒ Object
- #state ⇒ Object
- #with(*values) ⇒ Object
Constructor Details
#initialize(element, attributes_as_hash) ⇒ Custom
Returns a new instance of Custom.
63 64 65 66 67 68 69 70 |
# File 'lib/lolita/builder.rb', line 63 def initialize(element, attributes_as_hash) @element = element @options = {} @build_attributes = {} @conditions = {} set_attributes(attributes_as_hash) set_default_attribute_values end |
Instance Attribute Details
#build_attributes ⇒ Object
Returns the value of attribute build_attributes.
61 62 63 |
# File 'lib/lolita/builder.rb', line 61 def build_attributes @build_attributes end |
#options ⇒ Object
Returns the value of attribute options.
61 62 63 |
# File 'lib/lolita/builder.rb', line 61 def @options end |
Class Method Details
.create(element, *args) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/lolita/builder.rb', line 30 def create(element, *args) possible_builder = extract_args(*args) if possible_builder.is_a?(Hash) Lolita::Builder::Custom.new(element, possible_builder) else possible_builder end end |
.extract_args(*args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lolita/builder.rb', line 39 def extract_args(*args) if args && args.any? = args. || {} if args[0] && args[0].is_a?(self) args[0] elsif args[0].is_a?(String) || args[0].is_a?(Symbol) [:name] = args[0] if args[1] [:state] = args[1] end elsif else raise ArgumentError, "Don't know how to make builder from #{}." end else return {} end end |
Instance Method Details
#build ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/lolita/builder.rb', line 82 def build path = if conditions? switch_path do |name,state| if conditions_met? [fixed_name(name).to_sym,state.to_sym] else [self.name, self.state] end end else [self.name,self.state] end result = path + [] return result end |
#name ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/lolita/builder.rb', line 99 def name result = if build_attributes[:name].to_s.size > 0 fixed_name(build_attributes[:name]) else fixed_name(@name,build_attributes[:name]) end result.to_sym end |
#state ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/lolita/builder.rb', line 108 def state result = if build_attributes[:state] && build_attributes[:state].to_s.size > 0 build_attributes[:state] else @state end result.to_sym end |
#with(*values) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/lolita/builder.rb', line 72 def with(*values) new_values = self.class.extract_args(*values) if new_values.is_a?(Hash) @build_attributes = new_values else raise ArgumentError, "Can't build with other builder, use build on that builder!" end self end |