Module: Poms::Fields::Details

Extended by:
Details
Included in:
Poms::Fields, Details
Defined in:
lib/poms/fields/details.rb

Overview

Module to find details from for ex. attributes on poms items.

Instance Method Summary collapse

Instance Method Details

#age_rating(item) ⇒ Object

Returns the NICAM age rating of the item or ALL if no age rating exists



66
67
68
# File 'lib/poms/fields/details.rb', line 66

def age_rating(item)
  item.fetch('ageRating', 'ALL')
end

#broadcasters(item) ⇒ Object



25
26
27
28
29
# File 'lib/poms/fields/details.rb', line 25

def broadcasters(item)
  Array(item['broadcasters']).map do |key_value_pair|
    key_value_pair['value']
  end
end

#content_ratings(item) ⇒ Object

Returns an array containing zero or more content ratings of the item Possible content ratings are: ANGST, DISCRIMINATIE, DRUGS_EN_ALCOHOL, GEWELD, GROF_TAALGEBRUIK and SEKS



74
75
76
# File 'lib/poms/fields/details.rb', line 74

def content_ratings(item)
  item.fetch('contentRatings', [])
end

#descendants_of(item, type) ⇒ Object

Returns all the descendantOfs of the type given.

Parameters:

  • item

    The Poms Hash

  • type

    The type of descendantOfs we want



21
22
23
# File 'lib/poms/fields/details.rb', line 21

def descendants_of(item, type)
  item['descendantOf'].select { |descendant| descendant['type'] == type }
end

#description(item, type = 'MAIN') ⇒ Object

Returns the description, main by default



14
15
16
# File 'lib/poms/fields/details.rb', line 14

def description(item, type = 'MAIN')
  value_of_type(item, 'descriptions', type)
end

#mid(item) ⇒ Object



31
32
33
# File 'lib/poms/fields/details.rb', line 31

def mid(item)
  item['mid']
end

#parent(item, midref: nil) ⇒ Object

Finds a parent the data is “member of”. If :midref is given, it will look for the parent that matches that mid and return nil if not found. Without the :midref it will return the first parent.

Parameters:

  • item

    The Poms Hash

  • optional

    midref The midref of parent we seek.



51
52
53
54
55
56
57
# File 'lib/poms/fields/details.rb', line 51

def parent(item, midref: nil)
  if midref
    parents(item).find { |parent| parent['midRef'] == midref }
  else
    parents(item).first
  end
end

#parents(item) ⇒ Object

Returns the parents that the element is member of. Will always return an array.



61
62
63
# File 'lib/poms/fields/details.rb', line 61

def parents(item)
  Array(item['memberOf'])
end

#position(item, member_of: nil) ⇒ Object

Returns the index at which it is in the parent. When no :member_of keyword is given, it will return the first found index. Else, when a parent is found with matching member_of midref, it returns that index. Else returns nil. seek the index

Parameters:

  • item

    The Poms Hash

  • optional

    :member_of The midref of parent for which we



42
43
44
# File 'lib/poms/fields/details.rb', line 42

def position(item, member_of: nil)
  parent(item, midref: member_of).try(:[], 'index')
end

#title(item, type = 'MAIN') ⇒ Object

Returns the title, main by default



9
10
11
# File 'lib/poms/fields/details.rb', line 9

def title(item, type = 'MAIN')
  value_of_type(item, 'titles', type)
end