Class: Lebowski::Foundation::Views::Support::SimpleItemArray

Inherits:
Object
  • Object
show all
Includes:
Lebowski::Foundation, Lebowski::Foundation::Views
Defined in:
lib/lebowski/foundation/views/support/simple_item_array.rb

Direct Known Subclasses

RadioViewItemArray, SegmentItemArray

Constant Summary

Constants included from Lebowski::Foundation

SC_BRANCH_CLOSED, SC_BRANCH_OPEN, SC_LEAF_NODE, SC_MIXED_STATE, SC_PICKER_FIXED, SC_PICKER_MENU, SC_PICKER_POINTER, SC_T_ARRAY, SC_T_BOOL, SC_T_CLASS, SC_T_ERROR, SC_T_FUNCTION, SC_T_HASH, SC_T_NULL, SC_T_NUMBER, SC_T_OBJECT, SC_T_STRING, SC_T_UNDEFINED

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ SimpleItemArray

Returns a new instance of SimpleItemArray.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 43

def initialize(parent)
  if not parent.kind_of? View
    raise ArgumentInvalidTypeError.new "parent", parent, View
  end
  
  @parent = parent
  @driver = parent.driver
  @value_rel_path = 'value'
  @items_rel_path = 'items'
  @item_title_key = parent['itemTitleKey']
  @item_value_key = parent['itemValueKey']
end

Instance Method Details

#[](index) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 87

def [](index)
  if index < 0 or index > count
    raise ArgumentError "index must be between 0 and #{count}"
  end
  
  items = @parent[@items_rel_path]
  return __create_simple_item(items[index])
end

#all?(&block) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
118
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 115

def all?(&block)
  raise ArgumentError "require block" if (not block_given?)
  return (count(&block) == count)
end

#all_selected?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 75

def all_selected?()
  return (selected_count == count)
end

#any?(&block) ⇒ Boolean Also known as: some?

Returns:

  • (Boolean)


120
121
122
123
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 120

def any?(&block)
  raise ArgumentError "require block" if (not block_given?)
  return (count(&block) > 0)
end

#any_selected?Boolean Also known as: some_selected?

Returns:

  • (Boolean)


69
70
71
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 69

def any_selected?()
  return (selected_count > 0)
end

#click(value) ⇒ Object



158
159
160
161
162
163
164
165
166
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 158

def click(value)
  if value.kind_of? Integer
    click_with_index(value) 
  elsif value.kind_of? String
    click_with_title(value)
  else
    raise ArgumentInvalidTypeError.new "value", value, Integer, String
  end
end

#click_with_index(value) ⇒ Object

Must be implemented by a subclass



169
170
171
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 169

def click_with_index(value)
  # NO-OP
end

#click_with_title(value) ⇒ Object



173
174
175
176
177
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 173

def click_with_title(value)
  index = find_index_with_title value
  return if (index == :no_index)
  click_with_index index
end

#count(&block) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 105

def count(&block)
  return @parent["#{@items_rel_path}.length"] if (not block_given?)
  counter = 0
  each do |item, index|
    result = yield item, index
    counter = counter.next if (result == true)
  end
  return counter
end

#each(&block) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 96

def each(&block)
  items = @parent[@items_rel_path]
    
  items.each_with_index do |item, index|
    item = __create_simple_item(item)
    yield item, index
  end
end

#find_index_with_title(value) ⇒ Object



201
202
203
204
205
206
207
208
209
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 201

def find_index_with_title(value)
  items = @parent[@items_rel_path]      
  items.each_with_index do |item, index|
    title = get_item_title(item)
    return index if (title =~ /^#{value}/i)
  end
  
  return :no_index
end

#none?(&block) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
135
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 132

def none?(&block)
  raise ArgumentError "require block" if (not block_given?)
  return (count(&block) == 0)
end

#none_selected?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 83

def none_selected?()
  return (selected_count == 0)
end

#one?(&block) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
130
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 127

def one?(&block)
  raise ArgumentError "require block" if (not block_given?)
  return (count(&block) == 1)
end

#one_selected?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 79

def one_selected?()
  return (selected_count == 1)
end

#select(value) ⇒ Object



179
180
181
182
183
184
185
186
187
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 179

def select(value)
  if value.kind_of? Integer
    select_with_index(value) 
  elsif value.kind_of? String
    select_with_title(value)
  else
    raise ArgumentInvalidTypeError.new "value", value, Integer, String
  end
end

#select_with_index(index) ⇒ Object



189
190
191
192
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 189

def select_with_index(index)
  item = self[index]
  item.select
end

#select_with_title(value) ⇒ Object



194
195
196
197
198
199
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 194

def select_with_title(value)
  index = find_index_with_title(value)
  return if (index == :no_index)
  item = self[index]
  item.select
end

#selected?(value) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 56

def selected?(value)
  return selected_with_index?(value) if (value.kind_of? Integer)
  return selected_with_title?(value) if (value.kind_of? String)
  raise ArgumentInvalidTypeError.new "value", value, Integer, String
end

#selected_countObject



62
63
64
65
66
67
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 62

def selected_count()
  value = @parent[@value_rel_path]
  return 0 if value.nil?
  return value.length if value.kind_of?(Array)
  return 1
end

#selected_with_index?(index) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 137

def selected_with_index?(index)
  value = @parent[@value_rel_path]
  items = @parent[@items_rel_path]
  
  items.each_with_index do |item, idx|
    item_value = get_item_value(item)
    if index == idx 
      return (value == item_value) if (not value.kind_of? Array)
      return (value.member? item_value) if value.kind_of?(Array)
    end
  end
  
  return false
end

#selected_with_title?(value) ⇒ Boolean

Returns:

  • (Boolean)


152
153
154
155
156
# File 'lib/lebowski/foundation/views/support/simple_item_array.rb', line 152

def selected_with_title?(value)
  index = find_index_with_title value
  return false if (index == :no_index)
  return selected_with_index?(index)
end