Class: Writefully::Taxon
- Inherits:
-
Object
- Object
- Writefully::Taxon
- Defined in:
- lib/writefully/taxon.rb
Defined Under Namespace
Classes: EagerLoader
Instance Attribute Summary collapse
-
#existing ⇒ Object
readonly
Returns the value of attribute existing.
-
#incoming ⇒ Object
readonly
Returns the value of attribute incoming.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #build_attributes(token) ⇒ Object
- #get_difference ⇒ Object
-
#initialize(incoming, existing, type) ⇒ Taxon
constructor
A new instance of Taxon.
- #non_existing ⇒ Object
- #parameterized(items) ⇒ Object
- #selector ⇒ Object
- #type_attribute ⇒ Object
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
#existing ⇒ Object (readonly)
Returns the value of attribute existing.
3 4 5 |
# File 'lib/writefully/taxon.rb', line 3 def existing @existing end |
#incoming ⇒ Object (readonly)
Returns the value of attribute incoming.
3 4 5 |
# File 'lib/writefully/taxon.rb', line 3 def incoming @incoming end |
#type ⇒ Object (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_difference ⇒ Object
19 20 21 |
# File 'lib/writefully/taxon.rb', line 19 def get_difference (parameterized(incoming) - parameterized(existing)).map { |t| t.titleize } end |
#non_existing ⇒ Object
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 |
#selector ⇒ Object
15 16 17 |
# File 'lib/writefully/taxon.rb', line 15 def selector @selector ||= type.underscore.to_sym end |
#type_attribute ⇒ Object
23 24 25 |
# File 'lib/writefully/taxon.rb', line 23 def type_attribute selector == :'writefully/tag' ? { type: nil } : { type: selector.to_s.classify } end |