Class: CoaOpScraper::CoaDocketNo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(no) ⇒ CoaDocketNo

Encapsulating the logic of working with COA docket numbers. Note: Distinct from knowing if a valid docket number was actually used



7
8
9
10
11
12
13
14
# File 'lib/coa_docket_no.rb', line 7

def initialize(no)
  parts = no.split("-")
  if parts.count == 4 and (parts.last == "CR" or parts.last == "CV")
    @no = no
  else
    @no = nil
  end
end

Instance Attribute Details

#noObject

Returns the value of attribute no.



3
4
5
# File 'lib/coa_docket_no.rb', line 3

def no
  @no
end

Instance Method Details

#canonicalObject



72
73
74
# File 'lib/coa_docket_no.rb', line 72

def canonical
  self.fixed_length
end

#case_numberObject



48
49
50
# File 'lib/coa_docket_no.rb', line 48

def case_number
  self.canonical.split("-")[2]
end

#civil?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/coa_docket_no.rb', line 52

def civil?
  self.canonical.split("-")[3] == "CV"
end

#coa_numberObject

For accessing pieces



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

def coa_number
  self.canonical.split("-")[0]
end

#criminal?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/coa_docket_no.rb', line 56

def criminal?
  self.canonical.split("-")[3] == "CR"
end

#fixed_lengthObject



24
25
26
27
28
29
30
31
# File 'lib/coa_docket_no.rb', line 24

def fixed_length
  if self.valid?
    (coa,year,number,type_suffix) = @no.split("-")
    [padded(coa,2), padded(year,2), padded(number,5), type_suffix].join('-')
  else
    ""
  end
end

#for_database_keyObject

Standardizing how used internally



63
64
65
# File 'lib/coa_docket_no.rb', line 63

def for_database_key
  self.without_type
end

#for_web_urlsObject

because the -CV/-CR suffix is not relevant to uniqueness



68
69
70
# File 'lib/coa_docket_no.rb', line 68

def for_web_urls
  self.fixed_length
end

#to_sObject



20
21
22
# File 'lib/coa_docket_no.rb', line 20

def to_s
  self.fixed_length
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/coa_docket_no.rb', line 16

def valid?
  !@no.nil?
end

#without_typeObject



33
34
35
# File 'lib/coa_docket_no.rb', line 33

def without_type
  self.fixed_length.sub("-CR","").sub("-CV","")
end

#year_numberObject



44
45
46
# File 'lib/coa_docket_no.rb', line 44

def year_number
  self.canonical.split("-")[1]
end