Class: AfterTheDeadline::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Error

Returns a new instance of Error.



83
84
85
86
87
88
89
# File 'lib/after_the_deadline.rb', line 83

def initialize(hash)
  raise "#{self.class} must be initialized with a Hash" unless hash.kind_of?(Hash)
  [:string, :description, :precontext, :type, :url].each do |attribute|
    self.send("#{attribute}=", hash[attribute.to_s])
  end
  self.suggestions = hash['suggestions'].nil? ? [] : [*hash['suggestions']['option']]
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



81
82
83
# File 'lib/after_the_deadline.rb', line 81

def description
  @description
end

#precontextObject

Returns the value of attribute precontext.



81
82
83
# File 'lib/after_the_deadline.rb', line 81

def precontext
  @precontext
end

#stringObject

Returns the value of attribute string.



81
82
83
# File 'lib/after_the_deadline.rb', line 81

def string
  @string
end

#suggestionsObject

Returns the value of attribute suggestions.



81
82
83
# File 'lib/after_the_deadline.rb', line 81

def suggestions
  @suggestions
end

#typeObject

Returns the value of attribute type.



81
82
83
# File 'lib/after_the_deadline.rb', line 81

def type
  @type
end

#urlObject

Returns the value of attribute url.



81
82
83
# File 'lib/after_the_deadline.rb', line 81

def url
  @url
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


102
103
104
105
106
107
# File 'lib/after_the_deadline.rb', line 102

def eql?(other)
  self.class.equal?(other.class) &&
    string == other.string &&
    description == other.description &&
    type == other.type
end

#hashObject



110
111
112
# File 'lib/after_the_deadline.rb', line 110

def hash
  string.hash ^ description.hash ^ type.hash
end

#info(theme = nil) ⇒ Object



91
92
93
94
95
96
# File 'lib/after_the_deadline.rb', line 91

def info(theme = nil)
  return unless self.url
  uri = URI.parse self.url
  uri.query = (uri.query || '') + "&theme=#{theme}"
  Net::HTTP.get(uri).strip
end

#to_sObject



98
99
100
# File 'lib/after_the_deadline.rb', line 98

def to_s
  "#{self.string} (#{self.description})"
end