Class: Serel::Tag

Inherits:
Base
  • Object
show all
Defined in:
lib/serel/tag.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #all, associations, attribute, config, #find, finder_methods, #get, #initialize, #inspect, #meth, method_missing, #network, network_wide, new_relation, request, respond_to?, #type, with_ids

Constructor Details

This class inherits a constructor from Serel::Base

Class Method Details

.find_by_name(name) ⇒ Serel::Tag

Finds a tag by name

Parameters:

  • name (String)

    The name of the tag you wish to find

Returns:

  • (Serel::Tag)

    The tag returned by the Stack Exchange API



18
19
20
# File 'lib/serel/tag.rb', line 18

def self.find_by_name(name)
  new_relation('tag', :singular).url("tags/#{CGI.escape(name)}/info").get
end

.moderator_onlySerel::Relation

Retrieves tags which can only be added or removed by a moderator

Serel::Tag.moderator_only.get

This is a scoping method and can be combined with other scoping methods

Returns:



27
28
29
# File 'lib/serel/tag.rb', line 27

def self.moderator_only
  url("tags/moderator-only")
end

.requiredSerel::Relation

Retrieves tags that are required on the site

Serel::Tag.required.get

This is a scoping method and can be combined with other scoping methods.

Returns:



36
37
38
# File 'lib/serel/tag.rb', line 36

def self.required
  url("tags/required")
end

.synonymsSerel::Relation

Retrieves all the tag synonyms on the site

Serel::Tag.synonyms.get

This is a scoping method and can be combined with other scoping methods.

Returns:



45
46
47
# File 'lib/serel/tag.rb', line 45

def self.synonyms
  new_relation(:tag_synonym).url("tags/synonyms")
end

Instance Method Details

#faqObject



49
50
51
# File 'lib/serel/tag.rb', line 49

def faq
  type(:tag).url("tags/#{name}/faq")
end

Retrieves related tags.

Serel::Tag.find(1).related.get

This is a scoping method and can be combined with other scoping methods.

Returns:



58
59
60
# File 'lib/serel/tag.rb', line 58

def related
  type(:tag).url("tags/#{name}/related")
end

#top_answerers(period) ⇒ Object

Raises:

  • (ArgumentError)


62
63
64
65
# File 'lib/serel/tag.rb', line 62

def top_answerers(period)
  raise ArgumentError, 'period must be :all_time or :month' unless [:all_time, :month].include? period
  type(:tag_score).url("tags/#{name}/top-answerers/#{period}")
end

#top_askers(period) ⇒ Object

Raises:

  • (ArgumentError)


67
68
69
70
# File 'lib/serel/tag.rb', line 67

def top_askers(period)
  raise ArgumentError, 'period must be :all_time or :month' unless [:all_time, :month].include? period
  type(:tag_score).url("tags/#{name}/top-askers/#{period}")
end

#wikiObject



72
73
74
# File 'lib/serel/tag.rb', line 72

def wiki
  type(:tag_wiki, :singular).url("tags/#{name}/wikis").get
end