Class: Kilt::Object
- Inherits:
-
Object
- Object
- Kilt::Object
- Defined in:
- lib/kilt/object.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#type ⇒ Object
Returns the value of attribute type.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #empty? ⇒ Boolean
- #fill(params) ⇒ Object
-
#initialize(type, values = {}) ⇒ Object
constructor
A new instance of Object.
Constructor Details
#initialize(type, values = {}) ⇒ Object
Returns a new instance of Object.
5 6 7 8 9 10 |
# File 'lib/kilt/object.rb', line 5 def initialize(type, values = {}) @type = type @values = values assemble_fields end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
3 4 5 |
# File 'lib/kilt/object.rb', line 3 def fields @fields end |
#slug ⇒ Object
Returns the value of attribute slug.
3 4 5 |
# File 'lib/kilt/object.rb', line 3 def slug @slug end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/kilt/object.rb', line 3 def type @type end |
#values ⇒ Object
Returns the value of attribute values.
3 4 5 |
# File 'lib/kilt/object.rb', line 3 def values @values end |
Instance Method Details
#[](key) ⇒ Object
39 40 41 42 |
# File 'lib/kilt/object.rb', line 39 def [](key) # Return the values of the object as a hash @values[key.to_s].html_safe if @values[key.to_s] end |
#[]=(key, value) ⇒ Object
44 45 46 |
# File 'lib/kilt/object.rb', line 44 def []=(key, value) @values[key.to_s] = value end |
#empty? ⇒ Boolean
52 53 54 |
# File 'lib/kilt/object.rb', line 52 def empty? @values.length == 0 end |
#fill(params) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kilt/object.rb', line 12 def fill(params) puts params # Take the params passed in and match them up to the fields @fields.each do |key, value| if params[key] || params["#{key}-hidden"] field_type = value.downcase if ['file', 'image'].include? field_type if params["#{key}-hidden"] && params["#{key}-hidden"] == 'clear' && !params[key] @values[key.to_s] = '' elsif params[key] @values[key.to_s] = Kilt::Upload.send(field_type, params[key]) end else @values[key.to_s] = params[key] end end end # Add some extra fields if !@slug @values['slug'] = Utils.slugify(@values['name']) end @values['type'] = @type end |