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)
Constructor Details
#initialize(name) ⇒ Tag
Returns a new instance of Tag.
32 33 34 35 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 32 def initialize(name) super() @name = name end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
30 31 32 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 30 def created_at @created_at end |
#modified_at ⇒ Object
Returns the value of attribute modified_at.
30 31 32 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 30 def modified_at @modified_at end |
#name ⇒ Object
Returns the value of attribute name.
30 31 32 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 30 def name @name end |
Class Method Details
.dirty ⇒ Object
rubocop: disable Style/FormatStringToken
71 72 73 74 75 76 77 78 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 71 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
82 83 84 85 86 87 88 89 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 82 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
61 62 63 64 65 66 67 68 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 61 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
57 58 59 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 57 def <=>(other) self.name <=> other.name end |
#after_create ⇒ Object
42 43 44 45 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 42 def after_create super Inform.attributes.reset end |
#after_save ⇒ Object
47 48 49 50 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 47 def after_save super self.modified_at = Time.now.utc end |
#before_create ⇒ Object
37 38 39 40 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 37 def before_create self.created_at ||= Time.now super end |
#to_s ⇒ Object Also known as: to_str
52 53 54 |
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 52 def to_s name end |