Class: TheFuturest::Chapter

Inherits:
Object
  • Object
show all
Defined in:
lib/futurest/chapter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Chapter

Returns a new instance of Chapter.



5
6
7
8
9
# File 'lib/futurest/chapter.rb', line 5

def initialize(attrs)
  @id = attrs["id"]
  @title = attrs["title"]
  @number = attrs["number"]
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



3
4
5
# File 'lib/futurest/chapter.rb', line 3

def errors
  @errors
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/futurest/chapter.rb', line 3

def id
  @id
end

#numberObject

Returns the value of attribute number.



3
4
5
# File 'lib/futurest/chapter.rb', line 3

def number
  @number
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/futurest/chapter.rb', line 3

def title
  @title
end

Class Method Details

.find(id, query = {}) ⇒ Object



11
12
13
14
# File 'lib/futurest/chapter.rb', line 11

def self.find(id, query = {})
  response = Text.get("/chapter/#{id}", :query => query)
  self.new response.parsed_response
end

.parse(response) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/futurest/chapter.rb', line 16

def self.parse(response)
  chapter = response.parsed_response
  if chapter.is_a? Array
    chapter.map {|c| Chapter.new c }
  else
    Chapter.new chapter
  end
end

Instance Method Details

#paragraphs(query = {}) ⇒ Object



25
26
27
# File 'lib/futurest/chapter.rb', line 25

def paragraphs(query = {})
  Paragraph.parse Text.get("/chapter/#{@id}/paragraphs", :query => query)
end

#saveObject



29
30
31
32
33
# File 'lib/futurest/chapter.rb', line 29

def save
  response = Text.post("/chapter/#{@id}", :query => { :title => @title, :number => @number }).parsed_response
  @errors = response["errors"] and return false if response["errors"].any?
  true
end