Class: Rubyhexagon::Note
- Inherits:
-
Object
- Object
- Rubyhexagon::Note
- Defined in:
- lib/rubyhexagon/note.rb,
lib/rubyhexagon/api/note.rb
Overview
A class to interact with the e621 web interface.
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Text content of note.
-
#created_at ⇒ Time
readonly
Time of creation.
-
#creator ⇒ E621::User
readonly
User object of creator.
-
#height ⇒ Integer
readonly
Height of object.
-
#id ⇒ Integer
readonly
Id for this note.
-
#point ⇒ Array<Integer>
readonly
Combined position (x, y).
-
#post ⇒ E621::Post
readonly
Post this note belongs to.
-
#rect ⇒ Array<Integer>
readonly
Combined rectangular (x, y, width, height).
-
#updated_at ⇒ Time
readonly
Time of last update.
-
#version ⇒ Integer
readonly
Version of this note.
-
#width ⇒ Integer
readonly
Width of object.
-
#x ⇒ Integer
readonly
Position x value.
-
#y ⇒ Integer
readonly
Position y value.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for Notes, to give a more meaningful comparison.
-
#active? ⇒ TrueClass|FalseClass
Determine if note is active or not.
-
#initialize(note) ⇒ Object
constructor
Initializer for Note.
Constructor Details
#initialize(note) ⇒ Object
Initializer for Note.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rubyhexagon/note.rb', line 72 def initialize(note) raise ArgumentError, "#{note.class} is not a Hash" unless note.is_a?(Hash) raise ArgumentError, 'An id is required' if note[:id].nil? note.each do |k, v| if %i[id x y width height is_active version body].include?(k) if k == :id && !(v.is_a?(Integer) && v.positive?) raise InvalidIDError, "Invalid id: #{v}" end instance_variable_set("@#{k}".to_sym, v) elsif %i[created_at updated_at].include?(k) instance_variable_set("@#{k}".to_sym, Time.at(v[:s])) elsif k == :post_id @post = E621::Post.new(id: v) elsif k == :creator_id @creator = E621::User.new(id: v) end end @point = [@x, @y] @rect = [@x, @y, @width, @height] end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns text content of note.
60 61 62 |
# File 'lib/rubyhexagon/note.rb', line 60 def body @body end |
#created_at ⇒ Time (readonly)
Returns time of creation.
30 31 32 |
# File 'lib/rubyhexagon/note.rb', line 30 def created_at @created_at end |
#creator ⇒ E621::User (readonly)
Returns user object of creator.
36 37 38 |
# File 'lib/rubyhexagon/note.rb', line 36 def creator @creator end |
#height ⇒ Integer (readonly)
Returns height of object.
51 52 53 |
# File 'lib/rubyhexagon/note.rb', line 51 def height @height end |
#id ⇒ Integer (readonly)
Returns id for this note.
27 28 29 |
# File 'lib/rubyhexagon/note.rb', line 27 def id @id end |
#point ⇒ Array<Integer> (readonly)
Returns combined position (x, y).
45 46 47 |
# File 'lib/rubyhexagon/note.rb', line 45 def point @point end |
#post ⇒ E621::Post (readonly)
Returns post this note belongs to.
57 58 59 |
# File 'lib/rubyhexagon/note.rb', line 57 def post @post end |
#rect ⇒ Array<Integer> (readonly)
Returns combined rectangular (x, y, width, height).
54 55 56 |
# File 'lib/rubyhexagon/note.rb', line 54 def rect @rect end |
#updated_at ⇒ Time (readonly)
Returns time of last update.
33 34 35 |
# File 'lib/rubyhexagon/note.rb', line 33 def updated_at @updated_at end |
#version ⇒ Integer (readonly)
Returns version of this note.
63 64 65 |
# File 'lib/rubyhexagon/note.rb', line 63 def version @version end |
#width ⇒ Integer (readonly)
Returns width of object.
48 49 50 |
# File 'lib/rubyhexagon/note.rb', line 48 def width @width end |
#x ⇒ Integer (readonly)
Returns position x value.
39 40 41 |
# File 'lib/rubyhexagon/note.rb', line 39 def x @x end |
#y ⇒ Integer (readonly)
Returns position y value.
42 43 44 |
# File 'lib/rubyhexagon/note.rb', line 42 def y @y end |
Class Method Details
.history(query) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/rubyhexagon/api/note.rb', line 43 def self.history(query) raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash) E621::API.fetch(:note, :history, query).map do |note| new(note) end end |
.list(post) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubyhexagon/api/note.rb', line 25 def self.list(post) unless post.is_a?(Hash) || post.is_a?(E621::Post) raise ArgumentError, 'A Hash or Post object is required' end post.store(:post_id, post.delete(:id)) if post.is_a?(Hash) post = { post_id: post.id } if post.is_a?(E621::Post) E621::API.fetch(:note, :index, post).map do |note| new(note) end end |
.search(query) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rubyhexagon/api/note.rb', line 36 def self.search(query) raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash) E621::API.fetch(:note, :search, query).map do |note| new(note) end end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparison method for Notes, to give a more meaningful comparison.
108 109 110 |
# File 'lib/rubyhexagon/note.rb', line 108 def ==(other) other.is_a?(Note) && @id == other.id && @version == other.version end |
#active? ⇒ TrueClass|FalseClass
Determine if note is active or not.
98 99 100 101 |
# File 'lib/rubyhexagon/note.rb', line 98 def active? return false if @is_active.nil? @is_active end |