Class: TheFuturest::Paragraph

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Paragraph

Returns a new instance of Paragraph.



5
6
7
8
9
10
11
# File 'lib/futurest/paragraph.rb', line 5

def initialize(attrs)
  @id = attrs["id"]
  @number = attrs["number"]
  @text = attrs["text"]
  @styled_text = attrs["styled_text"]
  @chapter_id = attrs["chapter_id"]
end

Instance Attribute Details

#chapter_idObject

Returns the value of attribute chapter_id.



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

def chapter_id
  @chapter_id
end

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#styled_textObject

Returns the value of attribute styled_text.



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

def styled_text
  @styled_text
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.parse(response) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/futurest/paragraph.rb', line 13

def self.parse(response)
  paragraph = response.parsed_response
  if paragraph.is_a? Array
    paragraph.map {|p| Paragraph.new p }
  else
    Paragraph.new paragraph
  end
end

Instance Method Details

#chapterObject



22
23
24
# File 'lib/futurest/paragraph.rb', line 22

def chapter
  Chapter.parse Text.get("/chapter/#{@chapter_id}")
end

#saveObject



26
27
28
29
30
31
# File 'lib/futurest/paragraph.rb', line 26

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