Module: EverydayPlugins::TypeHelper

Defined in:
lib/everyday-plugins/plugin.rb

Instance Method Summary collapse

Instance Method Details

#basic_type(list, *args) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/everyday-plugins/plugin.rb', line 121

def basic_type(list, *args)
  options = Plugins.get_var :options
  list.any? { |item|
    if item[:block].nil?
      flag_boolean(item, options)
    else
      item[:block].call(options, *args)
    end
  }
end

#complex_filter(list, options, symbol) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/everyday-plugins/plugin.rb', line 136

def complex_filter(list, options, symbol)
  list.filtermap { |item|
    if item[:block].nil?
      if item[:options].has_key?(symbol) && flag_boolean(item, options)
        item[:options][symbol]
      else
        item[:options].has_key?(:option) && !options[item[:options][:option]].nil? ? options[item[:options][:option]] : false
      end
    else
      rval = item[:block].call(options)
      (rval.nil? || !rval) ? false : rval
    end
  }
end

#flag_boolean(item, options) ⇒ Object



132
133
134
# File 'lib/everyday-plugins/plugin.rb', line 132

def flag_boolean(item, options)
  item[:options].has_key?(:option) && options[item[:options][:option]] == (item[:options].has_key?(:value) ? item[:options][:value] : true)
end

#get_name(list) ⇒ Object



161
162
163
164
165
# File 'lib/everyday-plugins/plugin.rb', line 161

def get_name(list)
  options = Plugins.get_var :options
  rval    = complex_filter(list.sort_by { |v| -v[:options][:priority] }, options, :name)
  (rval.nil? || rval.empty?) ? false : rval.first
end

#simple_type(list, *args) ⇒ Object



151
152
153
154
# File 'lib/everyday-plugins/plugin.rb', line 151

def simple_type(list, *args)
  options = Plugins.get_var :options
  list.sort_by { |v| v[:options][:order] }.each { |item| item[:block].call(options, *args) }
end

#simple_type_with_result(list) ⇒ Object



156
157
158
159
# File 'lib/everyday-plugins/plugin.rb', line 156

def simple_type_with_result(list)
  result = Plugins.get_var :result
  simple_type(list, result)
end