Class: Heatwave::TrackingNumber::Result

Inherits:
Data
  • Object
show all
Defined in:
app/lib/heatwave/tracking_number/result.rb

Overview

One parse of a tracking number against the owned courier catalog.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracking_number: nil, courier_code: nil, courier_name: nil, service_type: nil, tracking_url: nil, spec_id: nil, checksum: false, valid: false) ⇒ void

Parameters:

  • tracking_number (String, nil) (defaults to: nil)
  • courier_code (Symbol, nil) (defaults to: nil)
  • courier_name (String, nil) (defaults to: nil)
  • service_type (String, nil) (defaults to: nil)
  • tracking_url (String, nil) (defaults to: nil)
  • spec_id (String, nil) (defaults to: nil)
  • checksum (Boolean) (defaults to: false)
  • valid (Boolean) (defaults to: false)


25
26
27
28
29
30
31
# File 'app/lib/heatwave/tracking_number/result.rb', line 25

def initialize(
  tracking_number: nil, courier_code: nil, courier_name: nil,
  service_type: nil, tracking_url: nil, spec_id: nil, checksum: false,
  valid: false
)
  super
end

Instance Attribute Details

#checksumObject (readonly)

Returns the value of attribute checksum

Returns:

  • (Object)

    the current value of checksum



6
7
8
# File 'app/lib/heatwave/tracking_number/result.rb', line 6

def checksum
  @checksum
end

#courier_codeObject (readonly)

Returns the value of attribute courier_code

Returns:

  • (Object)

    the current value of courier_code



6
7
8
# File 'app/lib/heatwave/tracking_number/result.rb', line 6

def courier_code
  @courier_code
end

#courier_nameObject (readonly)

Returns the value of attribute courier_name

Returns:

  • (Object)

    the current value of courier_name



6
7
8
# File 'app/lib/heatwave/tracking_number/result.rb', line 6

def courier_name
  @courier_name
end

#service_typeObject (readonly)

Returns the value of attribute service_type

Returns:

  • (Object)

    the current value of service_type



6
7
8
# File 'app/lib/heatwave/tracking_number/result.rb', line 6

def service_type
  @service_type
end

#spec_idObject (readonly)

Returns the value of attribute spec_id

Returns:

  • (Object)

    the current value of spec_id



6
7
8
# File 'app/lib/heatwave/tracking_number/result.rb', line 6

def spec_id
  @spec_id
end

#tracking_numberObject (readonly)

Returns the value of attribute tracking_number

Returns:

  • (Object)

    the current value of tracking_number



6
7
8
# File 'app/lib/heatwave/tracking_number/result.rb', line 6

def tracking_number
  @tracking_number
end

#tracking_urlObject (readonly)

Returns the value of attribute tracking_url

Returns:

  • (Object)

    the current value of tracking_url



6
7
8
# File 'app/lib/heatwave/tracking_number/result.rb', line 6

def tracking_url
  @tracking_url
end

#validObject (readonly)

Returns the value of attribute valid

Returns:

  • (Object)

    the current value of valid



6
7
8
# File 'app/lib/heatwave/tracking_number/result.rb', line 6

def valid
  @valid
end

Instance Method Details

#checksum?Boolean

Returns:

  • (Boolean)


37
# File 'app/lib/heatwave/tracking_number/result.rb', line 37

def checksum? = checksum

#confidenceFloat

Checksum-backed matches outrank format-only ones; longer numbers win
a checksum tie so a 22-digit IMpb beats a 12-digit fragment.

Returns:

  • (Float)


43
44
45
# File 'app/lib/heatwave/tracking_number/result.rb', line 43

def confidence
  (checksum? ? 5.0 : 0.0) + (tracking_number.to_s.length * 0.1)
end

#to_sString

Returns:

  • (String)


48
# File 'app/lib/heatwave/tracking_number/result.rb', line 48

def to_s = tracking_number.to_s # rubocop:disable Rails/Delegate

#valid?Boolean

Returns:

  • (Boolean)


34
# File 'app/lib/heatwave/tracking_number/result.rb', line 34

def valid? = valid