Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def parse_var(var)
- value = instance_variable_get(var)
- puts(value)
- puts(value.to_s)
- value.is_a?(Numeric) ? value.to_s : ""#{value}""
- end
- require 'securerandom'
- # Entity.rb
- class Entity
- def initialize
- generate_uuid
- end
- def to_cypher
- first_char = self.class.name.chr.downcase
- "MERGE (#{first_char}:#{self.class.name} {#{attrs_to_cypher.join(', ')}}) RETURN #{first_char};"
- end
- protected
- def rand_bool
- [true, false].sample
- end
- private
- def attrs_to_cypher
- self.instance_variables.map do |var|
- "#{camelize(var.to_s[1..-1])}:#{parse_var(var)}"
- end
- end
- def generate_uuid
- @uuid = SecureRandom.uuid
- end
- def parse_var(var)
- value = instance_variable_get(var)
- puts(value)
- puts(value.to_s)
- value.is_a?(Numeric) ? value.to_s : ""#{value}""
- end
- def camelize(s)
- (s == "uuid") ? "UUID" : s.downcase.split('_').map(&:capitalize).join
- end
- end
- require 'faker'
- require_relative 'Entity'
- # PhoneNumber.rb
- class PhoneNumber < Entity
- def initialize(**opts)
- super()
- @type = opts[:type] || rand_bool ? "cell" : "home"
- @number = opts[:number] || @type == "cell" ? Faker::PhoneNumber.cell_phone : Faker::PhoneNumber.phone_number,
- @country_code = opts[:country_code] || nil
- @area_code = opts[:area_code] || nil
- end
- end
- puts ["(684) 029-6183 x01024", nil]
- #⇒ (684) 029-6183 x01024
- #
- value = [*value].compact.join
- @number = opts[:number] || @type == "cell" ? Faker::PhoneNumber.cell_phone : Faker::PhoneNumber.phone_number,
- @number = (opts[:number] || @type == "cell") ? Faker::PhoneNumber.cell_phone : Faker::PhoneNumber.phone_number,
- @number = opts[:number] || (@type == "cell" ? Faker::PhoneNumber.cell_phone : Faker::PhoneNumber.phone_number),
- opts = { number: '123' }
- type = "cell"
- number = opts[:number] || type == "cell" ? "truthy" : "falsey",
- country = "some value"
- p number # => ["truthy", "some value"]
- p country # => "some value"
Add Comment
Please, Sign In to add comment