Class: API::Author

Inherits:
Object
  • Object
show all
Defined in:
lib/quintype/api/author.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(author) ⇒ Author

Returns a new instance of Author.



32
33
34
# File 'lib/quintype/api/author.rb', line 32

def initialize(author)
  @author = author
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



3
4
5
# File 'lib/quintype/api/author.rb', line 3

def author
  @author
end

Class Method Details

.find(params) ⇒ Object



24
25
26
27
28
29
# File 'lib/quintype/api/author.rb', line 24

def find(params)
  if authors = API.authors({ids: params}).presence
    author = authors.first
    wrap(author)
  end
end

.where(params) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/quintype/api/author.rb', line 16

def where(params)
  if params['ids'].kind_of? Array
    params['ids'] = params['ids'].join ","
  end
  authors = API.authors(params)
  wrap_all(authors)
end

.wrap(author) ⇒ Object



12
13
14
# File 'lib/quintype/api/author.rb', line 12

def wrap(author)
  new(author) if author
end

.wrap_all(authors) ⇒ Object



5
6
7
8
9
10
# File 'lib/quintype/api/author.rb', line 5

def wrap_all(authors)
  authors ||= []
  authors.is_a?(Array) ?
    authors.map { |a| wrap(a) } :
    wrap(authors)
end

Instance Method Details

#to_h(config = {}) ⇒ Object



36
37
38
# File 'lib/quintype/api/author.rb', line 36

def to_h(config={})
  author
end