Class: MdlSearch::Icon

Inherits:
Object
  • Object
show all
Defined in:
lib/mdl_search/icon.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, name, codepoint, group, keywords, is_new) ⇒ Icon

Returns a new instance of Icon.



8
9
10
11
12
13
14
15
# File 'lib/mdl_search/icon.rb', line 8

def initialize(key, name, codepoint, group, keywords, is_new)
  @key = key
  @name = name
  @codepoint = codepoint
  @group = group
  @keywords = keywords
  @is_new = is_new
end

Class Attribute Details

.groupsObject

Returns the value of attribute groups.



48
49
50
# File 'lib/mdl_search/icon.rb', line 48

def groups
  @groups
end

.iconsObject

Returns the value of attribute icons.



49
50
51
# File 'lib/mdl_search/icon.rb', line 49

def icons
  @icons
end

Instance Attribute Details

#codepointObject

Returns the value of attribute codepoint.



3
4
5
# File 'lib/mdl_search/icon.rb', line 3

def codepoint
  @codepoint
end

#groupObject

Returns the value of attribute group.



3
4
5
# File 'lib/mdl_search/icon.rb', line 3

def group
  @group
end

#is_newObject

Returns the value of attribute is_new.



3
4
5
# File 'lib/mdl_search/icon.rb', line 3

def is_new
  @is_new
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/mdl_search/icon.rb', line 3

def key
  @key
end

#keywordsObject

Returns the value of attribute keywords.



3
4
5
# File 'lib/mdl_search/icon.rb', line 3

def keywords
  @keywords
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/mdl_search/icon.rb', line 3

def name
  @name
end

Class Method Details

.allObject



51
52
53
# File 'lib/mdl_search/icon.rb', line 51

def all
  icons
end

.where(hash) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/mdl_search/icon.rb', line 55

def where(hash)
  return self.all if hash.nil?
  self.all.select do |icon|
    hash.all? do |key, val|
      icon.include_value?(key, val)
    end
  end
end

Instance Method Details

#classic_browser_keyObject



21
22
23
# File 'lib/mdl_search/icon.rb', line 21

def classic_browser_key
  "&#x#{@codepoint};"
end

#hit_query?(value, query) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mdl_search/icon.rb', line 34

def hit_query?(value, query)
  case query.class.name
  when 'String'
    value.to_s.downcase.include? query.downcase
  when 'TrueClass', 'FalseClass'
    value == query
  when 'Array'
    query.any? { |q| value.downcase.include? q.downcase }
  else
    false
  end
end

#include_value?(key, query) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
# File 'lib/mdl_search/icon.rb', line 25

def include_value?(key, query)
  value_of_key = instance_variable_get "@#{key}"
  if value_of_key.is_a? Array
    value_of_key.any? { |v| hit_query? v, query }
  else
    hit_query? value_of_key, query
  end
end

#modern_browser_keyObject



17
18
19
# File 'lib/mdl_search/icon.rb', line 17

def modern_browser_key
  @key
end