Class: Jbr::LineItem

Inherits:
Resource show all
Defined in:
lib/jbr/line_item.rb

Overview

One line of the work a job is made of: how many of a thing, and what it is called.

Direct Known Subclasses

Mock::LineItem

Constant Summary collapse

FIELDS =

What Jobber calls each field of a line.

%w[quantity name]
PAGE =

The most lines to read off one record. Bounded because Jobber prices a connection by the page it is asked for and prices an unbounded one at its own maximum, so the lines of a page of jobs were charged for as though every job had the largest job's worth of them.

20
SELECTION =

What to ask for wherever a record lists the lines it is made of.

"lineItems(first: #{PAGE}) { nodes { #{FIELDS.join ' '} } }"

Instance Attribute Summary

Attributes inherited from Resource

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Jbr::Resource

Class Method Details

.from(nodes) ⇒ Array<LineItem>

Returns one per line, in the order Jobber holds them.

Parameters:

  • nodes (Array<Hash>, nil)

    the lines as Jobber answered them, if it answered any.

Returns:

  • (Array<LineItem>)

    one per line, in the order Jobber holds them.



17
# File 'lib/jbr/line_item.rb', line 17

def self.from(nodes) = nodes.to_a.map { |node| new node: node }

Instance Method Details

#nameString?

Returns what the line is called.

Returns:

  • (String, nil)

    what the line is called.



23
# File 'lib/jbr/line_item.rb', line 23

def name = @node['name']

#quantityInteger, ...

Returns how many of it the job is for.

Returns:

  • (Integer, Float, nil)

    how many of it the job is for.



20
# File 'lib/jbr/line_item.rb', line 20

def quantity = whole @node['quantity']

#to_sString

Returns how many of what: 3 Bathroom Faucet Installation, and the name alone where Jobber holds no quantity for the line.

Returns:

  • (String)

    how many of what: 3 Bathroom Faucet Installation, and the name alone where Jobber holds no quantity for the line.



27
# File 'lib/jbr/line_item.rb', line 27

def to_s = [ quantity, name ].compact.join ' '