Class: Pipl::Job

Inherits:
Field show all
Defined in:
lib/pipl/fields.rb

Instance Attribute Summary collapse

Attributes inherited from Field

#current, #inferred, #last_seen, #valid_since

Instance Method Summary collapse

Methods inherited from Field

base_params_from_hash, extra_metadata, from_hash, #is_searchable?

Methods included from Utils

alnum_chars, alpha_chars, date_to_str, extract_rate_limits, is_valid_url?, str_to_date, titleize, to_utf8

Constructor Details

#initialize(params = {}) ⇒ Job

Returns a new instance of Job.



312
313
314
315
316
317
318
319
# File 'lib/pipl/fields.rb', line 312

def initialize(params={})
  super params
  @title = params[:title]
  @organization = params[:organization]
  @industry = params[:industry]
  @date_range = params[:date_range]
  @display = params[:display]
end

Instance Attribute Details

#date_rangeObject

Returns the value of attribute date_range.



310
311
312
# File 'lib/pipl/fields.rb', line 310

def date_range
  @date_range
end

#displayObject

Returns the value of attribute display.



310
311
312
# File 'lib/pipl/fields.rb', line 310

def display
  @display
end

#industryObject

Returns the value of attribute industry.



310
311
312
# File 'lib/pipl/fields.rb', line 310

def industry
  @industry
end

#organizationObject

Returns the value of attribute organization.



310
311
312
# File 'lib/pipl/fields.rb', line 310

def organization
  @organization
end

#titleObject

Returns the value of attribute title.



310
311
312
# File 'lib/pipl/fields.rb', line 310

def title
  @title
end

Instance Method Details

#to_hashObject



321
322
323
324
325
# File 'lib/pipl/fields.rb', line 321

def to_hash
  {title: @title, organization: @organization, industry: @industry,
   date_range: @date_range ? @date_range.to_hash : nil}
      .reject { |_, value| value.nil? }
end

#to_sObject



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/pipl/fields.rb', line 327

def to_s
  return @display if @display

  if @title && @organization
    s = @title + ' at ' + @organization
  else
    s = @title || @organization
  end

  if s && @industry
    if @date_range
      range = @date_range.years_range
      s += ' (%s, %d-%d)' % [@industry, range[0], range[1]]
    else
      s += ' (%s)' % [@industry]
    end
  else
    s = ((s || '') + ' ' + (@industry || '')).strip
    if s && @date_range
      range = @date_range.years_range
      s += ' (%d-%d)' % [range[0], range[1]]
    end
  end

  s ? Pipl::Utils.to_utf8(s) : ''
end