Class: Atome

Inherits:
Object
  • Object
show all
Includes:
Genesis, HeadlessRenderer, OpalRenderer, Render, Sanitizer, ServerRenderer
Defined in:
lib/atome/kernel/atome.rb,
lib/atome/version.rb,
lib/atome/extensions/sha.rb,
lib/atome/extensions/geolocation.rb,
lib/atome/kernel/properties/essential.rb,
lib/atome/renderers/opal/extensions/sha.rb,
lib/atome/renderers/opal/extensions/ping.rb,
lib/atome/renderers/opal/extensions/color.rb,
lib/atome/renderers/opal/extensions/geolocation.rb

Overview

rgb utility

Constant Summary collapse

VERSION =
'0.33341'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Render

#render_engine

Methods included from OpalRenderer

#alpha_html, #blue_html, #bottom_html, #drm_html, #green_html, #height_html, #id_html, #left_html, #parent_html, #red_html, #render_html, #right_html, #top_html, #type_html, #width_html

Methods included from HeadlessRenderer

#alpha_headless, #blue_headless, #bottom_headless, #drm_headless, #green_headless, #height_headless, #id_headless, #left_headless, #parent_headless, #red_headless, #render_headless, #right_headless, #top_headless, #type_headless, #width_headless

Methods included from ServerRenderer

#render_sever

Methods included from Sanitizer

#add_essential_drm, #add_essential_properties, #add_missing_id, #check_parent, default_params, #sanitizer, #validation

Methods included from Genesis

additional_atome_methods, additional_particle_methods, atome_creator, atome_creator_option, default_value, particle_creator, run_optional_methods_helper

Methods included from GenesisKernel

#additional_atomes, #create_new_atomes, #get_new_atome, #get_new_particle, #new_atome, #new_particle, #set_new_atome, #set_new_particle

Methods included from GenesisHelper

#broadcaster, #history

Constructor Details

#initialize(params = {}) ⇒ Atome

Returns a new instance of Atome.



84
85
86
87
88
89
90
91
92
# File 'lib/atome/kernel/atome.rb', line 84

def initialize(params = {})
  # # TODO: check if we need to add properties for the root object before sending the params
  # id_found = params.delete(:id)
  # params = { id: id_found }.merge(params)
  params.each do |atome, values|
    send(atome, values)
  end
  Universe.atomes_add(self)
end

Class Method Details

.atome(params) ⇒ Object



24
25
26
27
28
# File 'lib/atome/kernel/atome.rb', line 24

def self.atome(params)
  # id_found = params.delete(:id)
  # params = { id: id_found }.merge(params)
  Atome.new(params)
end

.current_machineObject



43
44
45
46
47
48
# File 'lib/atome/kernel/atome.rb', line 43

def self.current_machine
  platform = RUBY_PLATFORM.downcase
  output = `#{platform =~ /win32/ ? 'ipconfig /all' : 'ifconfig'}`
  current_machine_decision(platform, output)
  # TODO: check the code above and create a sensible identity
end

.current_machine_decision(platform, output) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/atome/kernel/atome.rb', line 30

def self.current_machine_decision(platform, output)
  case platform
  when /darwin/
    ::Regexp.last_match(1) if output =~ /en1.*?(([A-F0-9]{2}:){5}[A-F0-9]{2})/im
  when /win32/
    ::Regexp.last_match(1) if output =~ /Physical Address.*?(([A-F0-9]{2}-){5}[A-F0-9]{2})/im
  else
    # Cases for other platforms...
    'unknown platform'
  end
  platform
end

.current_userObject



50
51
52
# File 'lib/atome/kernel/atome.rb', line 50

def self.current_user
  @user
end

.current_user=(user) ⇒ Object



54
55
56
57
58
# File 'lib/atome/kernel/atome.rb', line 54

def self.current_user=(user)
  # TODO: create or load an existing user
  # if user needs to be create the current_user will be eVe
  @user = user
end

Instance Method Details

#[](params) ⇒ Object



30
31
32
# File 'lib/atome/kernel/properties/essential.rb', line 30

def [](params)
  instance_variable_get(instance_variables[params])
end

#add(params) ⇒ Object



14
15
16
# File 'lib/atome/kernel/properties/essential.rb', line 14

def add(params)
  puts "add : #{params}"
end

#additional(params = nil) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/atome/kernel/atome.rb', line 76

def additional(params = nil)
  if params
    additional_helper(params)
  else
    @additional
  end
end

#additional_helper(params) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/atome/kernel/atome.rb', line 64

def additional_helper(params)
  virtual_atome = Atome.new({})
  @additional = virtual_atome
  params.each_with_index do |additional, index|
    new_atome = Atome.new({})
    virtual_atome.instance_variable_set("@virtual#{index}", new_atome)
    additional.each do |param, value|
      new_atome.send(param, value)
    end
  end
end

#calculate_sha(string) ⇒ Object



2
3
4
# File 'lib/atome/extensions/sha.rb', line 2

def calculate_sha(string)
  Digest::SHA256.hexdigest(string)
end

#delete(params) ⇒ Object



26
27
28
# File 'lib/atome/kernel/properties/essential.rb', line 26

def delete(params)
  puts "replace : #{params}"
end

#geolocationObject



6
7
8
9
10
11
# File 'lib/atome/extensions/geolocation.rb', line 6

def geolocation
  # native version
  public_ip = `curl https://api.ipify.org`
  results = Geocoder.search(public_ip)
  results.first.coordinates
end

#identity(params) ⇒ Object



3
4
5
# File 'lib/atome/kernel/properties/essential.rb', line 3

def identity (params)
  @identity=params
end

#identity_generatorObject



60
61
62
# File 'lib/atome/kernel/atome.rb', line 60

def identity_generator
  { date: Time.now, location: geolocation }
end

#new(params) ⇒ Object



6
7
8
# File 'lib/atome/kernel/properties/essential.rb', line 6

def new(params)
  puts "add/new : #{params}"
end

#ping(address, my_proc = false) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/atome/renderers/opal/extensions/ping.rb', line 2

def ping(address, my_proc=false)
  ` var p = new Ping();
      p.ping('https://'+#{address}+'', function (err, data) {
          if (err) {
             return false;
          } else {
 console.log("the site "+#{address}+" is up!");
          }
      });
`
end

#replace(params) ⇒ Object



22
23
24
# File 'lib/atome/kernel/properties/essential.rb', line 22

def replace(params)
  puts "replace : #{params}"
end

#rgb_html(string) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/atome/renderers/opal/extensions/color.rb', line 5

def rgb_html(string)
  `
col = w3color(#{string});
rgb_col=col.toRgb();
return Opal.hash(rgb_col)
 `
end

#set(params) ⇒ Object



10
11
12
# File 'lib/atome/kernel/properties/essential.rb', line 10

def set(params)
  puts "set : #{params}"
end

#to_rgb(string) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/atome/renderers/opal/extensions/color.rb', line 13

def to_rgb(string)
  rgb_color = rgb_html(string)

  {
    red: rgb_color[:r] / 255,
    green: rgb_color[:g] / 255,
    blue: rgb_color[:b] / 255,
    alpha: 1
  }

end

#to_sObject



34
35
36
# File 'lib/atome/kernel/properties/essential.rb', line 34

def to_s
  inspect.to_s
end

#update(params) ⇒ Object



18
19
20
# File 'lib/atome/kernel/properties/essential.rb', line 18

def update(params)
  puts "update : #{params}"
end