Sha256: bf3aa42c7d29e002017617a51c2462a1d0ed82131f53bdfc31c8d713eaa2de78

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

class TwitterCldr.TerritoriesContainment
  @territories_data = `{{{territories_data}}}`

  @contains: (parent_code, child_code) ->
    @validate_territory(parent_code)
    @validate_territory(child_code)

    immediate_children = @children(parent_code)

    contains = false

    if child_code in immediate_children
      contains = true
    else
      for immediate_child in immediate_children
        if @contains(immediate_child, child_code)
          contains = true
          break

    contains

  @parents: (territory_code) ->
    @validate_territory(territory_code)
    @parents_data[territory_code]

  @children: (territory_code) ->
    @validate_territory(territory_code)
    @territories_data[territory_code] || []

  @prepare_parents_data: ->
    data = {}

    for territory, children of @territories_data
      data[territory] = [] unless territory of data

      for child in children
        data[child] = [] unless child of data
        data[child].push(territory)

    data

  @parents_data = @prepare_parents_data()

  @validate_territory: (territory_code) ->
    throw "unknown territory code" unless territory_code of @parents_data

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twitter_cldr_js-3.3.0 lib/twitter_cldr/js/mustache/implementation/shared/territories_containment.coffee
twitter_cldr_js-3.2.0 lib/twitter_cldr/js/mustache/implementation/shared/territories_containment.coffee
twitter_cldr_js-3.1.1 lib/twitter_cldr/js/mustache/implementation/shared/territories_containment.coffee
twitter_cldr_js-3.1.0 lib/twitter_cldr/js/mustache/implementation/shared/territories_containment.coffee