Class: Exegesis::Document::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/exegesis/document/attachment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, thing, doc) ⇒ Attachment

Returns a new instance of Attachment.



7
8
9
10
11
# File 'lib/exegesis/document/attachment.rb', line 7

def initialize(name, thing, doc)
  @document = doc
  @metadata = thing
  @name = name
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



5
6
7
# File 'lib/exegesis/document/attachment.rb', line 5

def document
  @document
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/exegesis/document/attachment.rb', line 5

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/exegesis/document/attachment.rb', line 5

def name
  @name
end

Instance Method Details

#content_typeObject



18
19
20
# File 'lib/exegesis/document/attachment.rb', line 18

def content_type
  @metadata['content_type']
end

#fileObject



30
31
32
# File 'lib/exegesis/document/attachment.rb', line 30

def file
  RestClient.get("#{document.database.uri}/#{document.id}/#{name}")
end

#lengthObject



22
23
24
# File 'lib/exegesis/document/attachment.rb', line 22

def length
  @metadata['length'] || -1
end

#stub?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/exegesis/document/attachment.rb', line 26

def stub?
  @metadata['stub'] || false
end

#to_jsonObject



34
35
36
37
38
39
40
# File 'lib/exegesis/document/attachment.rb', line 34

def to_json
  if @metadata['data']
    {'content_type' => @metadata['content_type'], 'data' => @metadata['data']}.to_json
  else
    @metadata.to_json
  end
end

#to_sObject Also known as: inspect



13
14
15
# File 'lib/exegesis/document/attachment.rb', line 13

def to_s
  "#<Exegesis::Document::Attachment document=#{@document.uri} #{@metadata.inspect}>"
end