Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new unit with a function #60

Open
apkowalewski0 opened this issue Sep 17, 2018 · 0 comments
Open

Create new unit with a function #60

apkowalewski0 opened this issue Sep 17, 2018 · 0 comments

Comments

@apkowalewski0
Copy link

apkowalewski0 commented Sep 17, 2018

I have been able to add in several new units by going into the derived_unit.yaml adding them directly into it. I need to add a unit that is converted by adding a constant. I want to have psia = psig + 14.696. I have created psig based on the [psi] unit and it works. When I try to convert psig to psia I get the following:

2.3.4 :007 > p = Unitwise(10, 'psig')
 => #<Unitwise::Measurement value=10 unit=psig>
2.3.4 :008 > p.convert_to('psia')
=> #<Unitwise::Measurement value=68947587.627683613367226734453442213195477645 unit=psia>

the definitition for psia and psig in derived_unit.yaml is

- :names: psig
  :symbol: psig
  :primary_code: psig
  :secondary_code: psig
  :scale:
    :value: 1.0
    :unit_code: "[psi]"
  :classification: misc
  :property: pressure
  :metric: false
  :special: false
  :arbitrary: false

- :names: psia
  :symbol: psia
  :primary_code: psia
  :secondary_code: psia
  :scale:
    :value: 1.0
    :unit_code: "psig"
    :function_code: psia
  :classification: misc
  :property: pressure
  :metric: false
  :special: true
  :arbitrary: false

and my functions in functional.rb are

  def self.to_psia(x)
      x + 14.696
    end`

   def self.from_psia(x)
      x - 14.696
    end

Is there something else that I need to add in to make sure that it is using the function properly? Or can you not add units that require functions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant