Class: Pixela::Graph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, graph_id:) ⇒ Graph

Returns a new instance of Graph.

Parameters:



13
14
15
16
# File 'lib/pixela/graph.rb', line 13

def initialize(client:, graph_id:)
  @client   = client
  @graph_id = graph_id
end

Instance Attribute Details

#clientPixela::Client (readonly)

Returns:



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

def client
  @client
end

#graph_idString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/pixela/graph.rb', line 9

def graph_id
  @graph_id
end

Instance Method Details

#create(name:, unit:, type:, color:) ⇒ Hashie::Mash

Create a new pixelation graph definition.

Examples:

client.graph("test-graph").create(name: "graph-name", unit: "commit", type: "int", color: "shibafu")

Parameters:

  • name (String)
  • unit (String)
  • type (String)
  • color (String)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



40
41
42
# File 'lib/pixela/graph.rb', line 40

def create(name:, unit:, type:, color:)
  client.create_graph(graph_id: graph_id, name: name, unit: unit, type: type, color: color)
end

#decrementHashie::Mash

Decrement quantity "Pixel" of the day (UTC).

Examples:

client.graph("test-graph").decrement

Returns:

  • (Hashie::Mash)

Raises:

See Also:



101
102
103
# File 'lib/pixela/graph.rb', line 101

def decrement
  client.decrement_pixel(graph_id: graph_id)
end

#incrementHashie::Mash

Increment quantity "Pixel" of the day (UTC).

Examples:

client.graph("test-graph").increment

Returns:

  • (Hashie::Mash)

Raises:

See Also:



87
88
89
# File 'lib/pixela/graph.rb', line 87

def increment
  client.increment_pixel(graph_id: graph_id)
end

#pixel(date = Date.today) ⇒ Pixela::Pixel

Parameters:

  • date (Date, Time) (defaults to: Date.today)

Returns:



21
22
23
# File 'lib/pixela/graph.rb', line 21

def pixel(date = Date.today)
  Pixel.new(client: client, graph_id: graph_id, date: date)
end

#update(name:, unit:, color:) ⇒ Hashie::Mash

Update predefined pixelation graph definitions.

Examples:

client.graph("test-graph").update(name: "graph-name", unit: "commit", color: "shibafu")

Parameters:

  • name (String)
  • unit (String)
  • color (String)

Returns:

  • (Hashie::Mash)

Raises:

See Also:



73
74
75
# File 'lib/pixela/graph.rb', line 73

def update(name:, unit:, color:)
  client.update_graph(graph_id: graph_id, name: name, unit: unit, color: color)
end

#url(date: nil) ⇒ String

Get graph url

Examples:

client.graph("test-graph").url
client.graph("test-graph").url(date: Date.new(2018, 3, 31))

Parameters:

  • date (Date, Time) (defaults to: nil)

Returns:

  • (String)

See Also:



55
56
57
# File 'lib/pixela/graph.rb', line 55

def url(date: nil)
  client.graph_url(graph_id: graph_id, date: date)
end