Class: Shard::Gist

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

Constant Summary collapse

SHARD_FILENAME =

# Declarations #

#
/(?:^(\w+)\.)?shard\.rb$/

Instance Method Summary collapse

Constructor Details

#initialize(gist_hash) ⇒ Gist

# Constructor #

#


21
22
23
# File 'lib/shard/gist.rb', line 21

def initialize(gist_hash)
  @gist_hash = gist_hash
end

Instance Method Details

#all_filesObject

# Instance Methods #

#


31
32
33
# File 'lib/shard/gist.rb', line 31

def all_files
  files.values
end

#descriptionObject



35
36
37
# File 'lib/shard/gist.rb', line 35

def description
  @gist_hash.description
end

#idObject



39
40
41
# File 'lib/shard/gist.rb', line 39

def id
  @gist_hash.id
end

#nameObject



43
44
45
46
47
# File 'lib/shard/gist.rb', line 43

def name
  match = shard_file.filename.match(SHARD_FILENAME)

  match[1] || id
end

#ruby_filesObject



49
50
51
# File 'lib/shard/gist.rb', line 49

def ruby_files
  files.select { |filename| filename =~ /\.rb$/ }.values
end

#shard_fileObject



53
54
55
# File 'lib/shard/gist.rb', line 53

def shard_file
  files.select { |filename| filename =~ SHARD_FILENAME }.values.first
end

#urlObject



57
58
59
# File 'lib/shard/gist.rb', line 57

def url
  @gist_hash.html_url
end

#usernameObject



61
62
63
# File 'lib/shard/gist.rb', line 61

def username
  @gist_hash.user.
end

#valid_shard?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/shard/gist.rb', line 65

def valid_shard?
  ! shard_file.nil?
end