class Lebowski::Foundation::Views::Support::SimpleItemArray
Public Class Methods
new(parent)
click to toggle source
# 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
Public Instance Methods
[](index)
click to toggle source
# 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)
click to toggle source
# 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?()
click to toggle source
# File lib/lebowski/foundation/views/support/simple_item_array.rb, line 75 def all_selected?() return (selected_count == count) end
any?(&block)
click to toggle source
# 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
Also aliased as: some?
any_selected?()
click to toggle source
# File lib/lebowski/foundation/views/support/simple_item_array.rb, line 69 def any_selected?() return (selected_count > 0) end
Also aliased as: some_selected?
click(value)
click to toggle source
# 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)
click to toggle source
Must be implemented by a subclass
# File lib/lebowski/foundation/views/support/simple_item_array.rb, line 169 def click_with_index(value) # NO-OP end
click_with_title(value)
click to toggle source
# 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() { |item, index| ... }
click to toggle source
# 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() { |item, index| ... }
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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?()
click to toggle source
# File lib/lebowski/foundation/views/support/simple_item_array.rb, line 83 def none_selected?() return (selected_count == 0) end
one?(&block)
click to toggle source
# 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?()
click to toggle source
# File lib/lebowski/foundation/views/support/simple_item_array.rb, line 79 def one_selected?() return (selected_count == 1) end
select(value)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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_count()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
create_simple_item(title, value)
click to toggle source
# File lib/lebowski/foundation/views/support/simple_item_array.rb, line 213 def create_simple_item(title, value) return SimpleItem.new self, title, value end
get_item_title(item)
click to toggle source
# File lib/lebowski/foundation/views/support/simple_item_array.rb, line 217 def get_item_title(item) return item if item.kind_of? String return item[@item_title_key] end
get_item_value(item)
click to toggle source
# File lib/lebowski/foundation/views/support/simple_item_array.rb, line 222 def get_item_value(item) return item if item.kind_of? String return item[@item_value_key] end
Private Instance Methods
__create_simple_item(item)
click to toggle source
# File lib/lebowski/foundation/views/support/simple_item_array.rb, line 229 def __create_simple_item(item) return create_simple_item(get_item_title(item), get_item_value(item)) end