Class: GReader::Tag

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/greader/tag.rb

Overview

A tag.

Common usage

Getting tags:

tag = @client.tag('TAG_ID')   # see Tag#id below

Metadata:

tag.to_s          #=> "Comics"
tag.id            #=> "user/1000/tag/Comics"

Collections:

tag.feeds         #=> [#<Feed "xkcd">, #<Feed "Dilbert">, ...]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#escape, #kv_map, #slug, #strip_tags

Constructor Details

#initialize(client, options) ⇒ Tag

Returns a new instance of Tag.



34
35
36
37
38
39
# File 'lib/greader/tag.rb', line 34

def initialize(client, options)
  @client  = client
  @options = options
  @id      = options['id']
  @sortid  = options['sortid']
end

Instance Attribute Details

#clientClient (readonly)

A link to Client.

Returns:



32
33
34
# File 'lib/greader/tag.rb', line 32

def client
  @client
end

#idstring (readonly)

The ID. Also used for Client#tag.

Returns:

  • (string)


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

def id
  @id
end

#sortidstring (readonly)

A sortable field.

Returns:

  • (string)


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

def sortid
  @sortid
end

Instance Method Details

#<=>(other) ⇒ Object



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

def <=>(other)
  sortid <=> other.sortid
end

#entries(options = {}) ⇒ Entries

List of entries.

Options

limit

The number of items (default 20)

order

The order of items; :desc is recent first, :asc is earliest first (default :desc)

start_time

The time (Time object) from which to start getting items. Only applicable if order is :asc.

Quirks

The results are cached. If you want to purge the cache, use #expire!.

Examples:


@client.feeds[2].entries
@client.feeds[2].entries limit: 10
@client.feeds[2].entries order: :asc, start_time: Time.now-86400

Returns:

  • (Entries)

    The entries it contains.



60
61
62
# File 'lib/greader/tag.rb', line 60

def entries(options={})
  @entries ||= Entries.fetch @client, "stream/contents/#{escape id}"
end

#expire!Object

Expires the cache.

Returns:

  • nil



66
67
68
# File 'lib/greader/tag.rb', line 66

def expire!
  @entries = nil
end

#feedsFeed[]

Returns a list of feeds.

Returns:



55
56
57
# File 'lib/greader/tag.rb', line 55

def feeds
  @client.feeds.select { |feed| feed.tags.include?(self) }
end

#to_paramObject



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

def to_param
  slug @id
end

#to_sObject



41
42
43
# File 'lib/greader/tag.rb', line 41

def to_s
  @id.split('/').last
end