Sha256: 541d3ad691744db87cfafd4a866786cd1f75d3462ea526db0ceb9249640f747e

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

module Nyaplot
  # The wrapper for countries
  # @see https://github.com/mledoze/countries
  # @see http://nbviewer.ipython.org/github/domitry/Nyaplot/blob/master/examples/notebook/Mapnya.ipynb
  class Countries
    class << self
      path = File.expand_path("../datasets/countries/countries.json", __FILE__)
      file = File.read(path)
      df = Nyaplot::DataFrame.new(JSON.parse(file))

      # pre-process
      lat = []; lng = []
      df.column(:latlng).each do |latlng|
        lat.push(latlng[0])
        lng.push(latlng[1])
      end
      df.insert_column(:lat, lat)
      df.insert_column(:lng, lng)
      df.delete_column(:latlng)

      # ATA have a problem on coordinate and BMU will cause that all ocean are filled in the same color as BMU's
      df.filter! {|row| !(row[:lat].nil? || row[:lng].nil? || ["BMU", "ATA"].index(row[:cca3]))}
      df.each_row {|row| row[:area]=0 if row[:area]<0}
      @@df = df

      # World countries list
      # @return [Array<String>] the list of world countries
      def countries_list
        @@df[:name].to_a
      end

      # CCA3 country code
      # @return [Array<String>] tye list of cca3 code
      def cca3_list
        @@df[:cca3].to_a
      end

      # The dataframe as the wrapper of countries
      # @return [DataFrame]
      def df
        @@df
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
nyaplot-0.1.6 lib/mapnya/countries.rb
nyaplot-0.1.5 lib/mapnya/countries.rb
nyaplot-0.1.4 lib/mapnya/countries.rb
nyaplot-0.2.0.rc1 lib/mapnya/countries.rb
nyaplot-0.1.3 lib/mapnya/countries.rb
nyaplot-0.1.2 lib/mapnya/countries.rb
nyaplot-0.1.1 lib/mapnya/countries.rb
nyaplot-0.1.0 lib/mapnya/countries.rb