Class: Gist

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Gist

Returns a new instance of Gist.



6
7
8
9
10
11
# File 'lib/gist.rb', line 6

def initialize(hash)
  @id = hash[:id]
  @description = hash[:description]
  @public = hash[:public]
  @files = hash[:files] || {}
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/gist.rb', line 5

def description
  @description
end

#filesObject

Returns the value of attribute files.



5
6
7
# File 'lib/gist.rb', line 5

def files
  @files
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/gist.rb', line 5

def id
  @id
end

#publicObject

Returns the value of attribute public.



5
6
7
# File 'lib/gist.rb', line 5

def public
  @public
end

Class Method Details

.json_create(hash) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/gist.rb', line 39

def self.json_create(hash)
  files = {}
  hash[:files].each do |k,v|
    files[k.to_s] = {:content => v[:content]}
  end

  hash[:files] = files

  new(hash)
end

Instance Method Details

#[](name) ⇒ Object



28
29
30
# File 'lib/gist.rb', line 28

def [](name)
  @files[name][:content]
end

#[]=(name, body) ⇒ Object



32
33
34
35
36
37
# File 'lib/gist.rb', line 32

def []=(name, body)
  if @files[name].nil? then
    @files[name] = {}
  end
  @files[name][:content] = body
end

#to_hashObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/gist.rb', line 13

def to_hash
  hash = {
    :description => @description,
    :public => @public,
    :files => @files,
  }
  hash[:id] = @id if not @id.nil?

  hash
end

#to_json(*a) ⇒ Object



24
25
26
# File 'lib/gist.rb', line 24

def to_json(*a)
  self.to_hash.to_json(*a)
end