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, what it is called, and what doing it involves.

Direct Known Subclasses

Mock::LineItem

Constant Summary collapse

FIELDS =

What Jobber calls each field of a line.

%w[quantity name description]
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.



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

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

Instance Method Details

#descriptionString?

Returns what doing it involves, in whoever wrote the line's own words.

Returns:

  • (String, nil)

    what doing it involves, in whoever wrote the line's own words.



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

def description = @node['description']

#nameString?

Returns what the line is called.

Returns:

  • (String, nil)

    what the line is called.



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

def name = @node['name']

#quantifiedString

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.



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

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

#quantityInteger, ...

Returns how many of it the job is for.

Returns:

  • (Integer, Float, nil)

    how many of it the job is for.



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

def quantity = whole @node['quantity']

#to_sString

Returns how a line reads: 3 Faucet install (Fits a new faucet), and without the parenthesis where nobody described it.

Returns:

  • (String)

    how a line reads: 3 Faucet install (Fits a new faucet), and without the parenthesis where nobody described it.



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

def to_s = [ quantified, described ].compact.join ' '