Class: NestedSelect::Item
- Inherits:
-
Object
- Object
- NestedSelect::Item
- Includes:
- NestedSelect
- Defined in:
- lib/nested_list/nested_select.rb
Direct Known Subclasses
Constant Summary collapse
- @@use_spaces =
true
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #find_by_name(name_tmp) ⇒ Object
- #full_name ⇒ Object
-
#initialize(name, id) ⇒ Item
constructor
A new instance of Item.
- #items_count ⇒ Object
- #parents_count ⇒ Object
- #spaces ⇒ Object
- #wrap ⇒ Object
Methods included from NestedSelect
Constructor Details
#initialize(name, id) ⇒ Item
11 12 13 14 15 |
# File 'lib/nested_list/nested_select.rb', line 11 def initialize(name, id) @name = name.to_s.strip @id = id.to_s @parent = nil end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/nested_list/nested_select.rb', line 9 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/nested_list/nested_select.rb', line 9 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/nested_list/nested_select.rb', line 9 def parent @parent end |
Instance Method Details
#find_by_name(name_tmp) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/nested_list/nested_select.rb', line 25 def find_by_name(name_tmp) if !self.name.empty? && self.full_name == name_tmp self.parent else false end end |
#full_name ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nested_list/nested_select.rb', line 46 def full_name unless @full_name_str item = self full_name = [] full_name << name while item = item.parent full_name << item.name end # Remove last general for all element full_name.pop full_name_str = parameterized_name(full_name.reverse!) end @full_name_str ||= full_name_str end |
#items_count ⇒ Object
42 43 44 |
# File 'lib/nested_list/nested_select.rb', line 42 def items_count 1 end |
#parents_count ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/nested_list/nested_select.rb', line 33 def parents_count item = self count = 0 while item = item.parent count += 1 end count end |
#spaces ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/nested_list/nested_select.rb', line 17 def spaces space = "" if @@use_spaces (parents_count-1).to_i.times{|i| space+=' '} end space end |
#wrap ⇒ Object
61 62 63 |
# File 'lib/nested_list/nested_select.rb', line 61 def wrap self.id && !self.id.empty? ? "<option value='#{self.id}' class='level_#{parents_count} item'>#{spaces}#{name.humanize}</option>" : "" end |