Class: E621::Tag
- Inherits:
-
Object
- Object
- E621::Tag
- Defined in:
- lib/rubyhexagon/tag.rb
Overview
Class to hold tag information.
Instance Attribute Summary collapse
-
#count ⇒ Integer
readonly
Number of posts that have this tag assigned to them.
-
#id ⇒ Integer
readonly
Id of tag.
-
#name ⇒ String
readonly
Name of tag.
-
#type ⇒ Type
readonly
Type of this tag.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison operator for Tag, to override the default one.
-
#initialize(id) ⇒ Object
constructor
Initializer for Tag.
-
#show(tag = nil) ⇒ Tag
Method to return a properly filled Tag object.
-
#show!(tag = nil) ⇒ NilClass
Bang method to fill tag data.
Constructor Details
#initialize(id) ⇒ Object
Initializer for Tag.
44 45 46 47 48 49 |
# File 'lib/rubyhexagon/tag.rb', line 44 def initialize(id) unless id.is_a?(Integer) && id > 0 raise InvalidIDError, "ID out of range: #{id}" end @id = id end |
Instance Attribute Details
#count ⇒ Integer (readonly)
Returns number of posts that have this tag assigned to them.
30 31 32 |
# File 'lib/rubyhexagon/tag.rb', line 30 def count @count end |
#id ⇒ Integer (readonly)
Returns id of tag.
24 25 26 |
# File 'lib/rubyhexagon/tag.rb', line 24 def id @id end |
#name ⇒ String (readonly)
Returns name of tag.
27 28 29 |
# File 'lib/rubyhexagon/tag.rb', line 27 def name @name end |
#type ⇒ Type (readonly)
Returns type of this tag.
33 34 35 |
# File 'lib/rubyhexagon/tag.rb', line 33 def type @type end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Note:
This method looks for same id and same name only.
Note:
If there is only a an ID set with one argument, then only compare IDs
Comparison operator for Tag, to override the default one.
92 93 94 95 96 97 98 99 |
# File 'lib/rubyhexagon/tag.rb', line 92 def ==(other) return false unless other.is_a?(Tag) if @name.nil? || other.name.nil? @id == other.id else @id == other.id && @name == other.name end end |
#show(tag = nil) ⇒ Tag
Note:
This makes an additional API call if no argument is given
Method to return a properly filled Tag object.
76 77 78 79 80 |
# File 'lib/rubyhexagon/tag.rb', line 76 def show(tag = nil) new_tag = Tag.new(@id) new_tag.show!(tag) new_tag end |
#show!(tag = nil) ⇒ NilClass
Bang method to fill tag data.
60 61 62 63 64 65 66 |
# File 'lib/rubyhexagon/tag.rb', line 60 def show!(tag = nil) tag = API.new.fetch('tag', 'show', id: @id) if tag.nil? @name = tag[:name] @count = tag[:count].to_i @type = (Type.new(tag[:type], tag[:type_locked]) unless tag[:type].nil?) nil end |