Class: Writefully::Taxon

Inherits:
Object
  • Object
show all
Defined in:
lib/writefully/taxon.rb

Defined Under Namespace

Classes: EagerLoader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming, existing, type) ⇒ Taxon

Returns a new instance of Taxon.



5
6
7
8
9
# File 'lib/writefully/taxon.rb', line 5

def initialize(incoming, existing, type)
  @incoming = incoming
  @existing = existing
  @type     = type
end

Instance Attribute Details

#existingObject (readonly)

Returns the value of attribute existing.



3
4
5
# File 'lib/writefully/taxon.rb', line 3

def existing
  @existing
end

#incomingObject (readonly)

Returns the value of attribute incoming.



3
4
5
# File 'lib/writefully/taxon.rb', line 3

def incoming
  @incoming
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/writefully/taxon.rb', line 3

def type
  @type
end

Instance Method Details

#build_attributes(token) ⇒ Object



27
28
29
30
# File 'lib/writefully/taxon.rb', line 27

def build_attributes token
  type_attribute
    .merge({ name: token, slug: token.parameterize })
end

#get_differenceObject



19
20
21
# File 'lib/writefully/taxon.rb', line 19

def get_difference
  (parameterized(incoming) - parameterized(existing)).map { |t| t.titleize }
end

#non_existingObject



11
12
13
# File 'lib/writefully/taxon.rb', line 11

def non_existing
  get_difference.map { |token| Tag.new(build_attributes(token)) }
end

#parameterized(items) ⇒ Object



32
33
34
# File 'lib/writefully/taxon.rb', line 32

def parameterized items
  items.map { |t| t.parameterize }
end

#selectorObject



15
16
17
# File 'lib/writefully/taxon.rb', line 15

def selector
  @selector ||= type.underscore.to_sym
end

#type_attributeObject



23
24
25
# File 'lib/writefully/taxon.rb', line 23

def type_attribute 
  selector == :'writefully/tag' ? { type: nil } : { type: selector.to_s.classify }
end