Class: PictoElement

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection, Mongoid::Document, Mongoid::Search, Mongoid::Timestamps
Defined in:
app/models/picto_element.rb

Class Method Summary collapse

Class Method Details

.method_missing(m, *args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/picto_element.rb', line 25

def self.method_missing(m, *args)
  if args.size == 1
    match = /_\w*_/.match m
    if match
      type = match.to_a[0]
      type.chop!.slice!(0)
      picto_hash = args[0].merge(category: type.parameterize.underscore.to_sym)
      PictoElement.create(picto_hash)
    end
  elsif args.size.zero?
    match = /_\w*/.match m
    if match
      type = match.to_a[0]
      type.slice!(0)
      PictoQuery
        .new
        .from_category(type.parameterize.underscore.to_sym)
        .to_a
    end
  end
end