Class: Inform::Ephemeral::Tag
- Defined in:
- lib/story_teller/inform/ephemeral/tag.rb
Overview
class Tag
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#modified_at ⇒ Object
Returns the value of attribute modified_at.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
-
.dirty ⇒ Object
rubocop: disable Style/FormatStringToken.
-
.stats ⇒ Object
rubocop: disable Style/FormatStringToken.
- .tidy ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #after_create ⇒ Object
- #after_save ⇒ Object
- #before_create ⇒ Object
-
#initialize(name) ⇒ Tag
constructor
A new instance of Tag.
- #to_s ⇒ Object (also: #to_str)
Methods inherited from Tag
Methods included from AdapterClassDelegation
#===, #delegated_adapter_class, #method_missing, #respond_to_missing?
Constructor Details
#initialize(name) ⇒ Tag
Returns a new instance of Tag.
31 32 33 34 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 31 def initialize(name) super() @name = name end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
29 30 31 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 29 def created_at @created_at end |
#modified_at ⇒ Object
Returns the value of attribute modified_at.
29 30 31 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 29 def modified_at @modified_at end |
#name ⇒ Object
Returns the value of attribute name.
29 30 31 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 29 def name @name end |
Class Method Details
.dirty ⇒ Object
rubocop: disable Style/FormatStringToken
70 71 72 73 74 75 76 77 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 70 def self.dirty results = db.fetch %(select a.id, a.name from tag a group by a.id, a.name having ((select count(b.id) from tagged b where b.tag_id = a.id) = 0)) return nil if results.empty? s = [format('%5s %20s', *results.first.keys)] s.concat(results.collect { |row| format('%5d %20s', *row.values) }) s.join("\n") end |
.stats ⇒ Object
rubocop: disable Style/FormatStringToken
81 82 83 84 85 86 87 88 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 81 def self.stats results = db.fetch %(select a.*, count(a.id) as "number tagged" from tag a, tagged b where b.tag_id = a.id group by a.id, a.name) return nil if results.empty? s = [format('%5s %20s %15s', *results.first.keys)] s.concat(results.collect { |row| format('%5d %20s %15s', *row.values) }) s.join("\n") end |
.tidy ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 60 def self.tidy db << %(delete from tag where id in (select a.id from tag a group by a.id, a.name having ((select count(b.id) from tagged b where b.tag_id = a.id) = 0))) Inform.attributes.reset return nil end |
Instance Method Details
#<=>(other) ⇒ Object
56 57 58 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 56 def <=>(other) self.name <=> other.name end |
#after_create ⇒ Object
41 42 43 44 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 41 def after_create super Inform.attributes.reset end |
#after_save ⇒ Object
46 47 48 49 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 46 def after_save super self.modified_at = Time.now.utc end |
#before_create ⇒ Object
36 37 38 39 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 36 def before_create self.created_at ||= Time.now super end |
#to_s ⇒ Object Also known as: to_str
51 52 53 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 51 def to_s name end |