<commit_before>module Skr

    class Uom < Skr::Model

        belongs_to :sku, :inverse_of=>:uoms

        validates :price,  :numericality=>true, :allow_nil=>false
        validates :sku,    :presence=>true, :on=>:update
        validates :code,   :presence=>true
        validates :size,   :numericality => true, :length=>{:minimum=>1}
        validates :weight, :height, :width, :depth, :numericality=>{:greater_than=>0.1}, :allow_nil=>true

        export_methods :combined_uom, mandatory: true

        def combined_uom
            if self.size.nil? || self.code.nil?
                ''
            elsif 1 == self.size
                self.code
            else
                "#{self.code}/#{self.size}"
            end
        end

        def has_dimensions?
            ! self.dimensions.include?(nil)
        end

        def dimensions
            [ width, height, depth ]
        end

        def volume
            if has_dimensions?
                dimensions.inject(:*)
            else
                nil
            end
        end

        def blank?
            self.code.blank? || self.size.to_i == 0
        end


        def self.ea
            Uom.new({ :code=>'EA',:size=>1, :price=>0.0 })
        end

    end


end # Skr module


__END__

        def for_public(user=nil,options={})
            as_json({
                :only=>%w{ code size base_price },
                :methods=>%w{ combined_uom dimensions volume }
            })
        end<commit_msg>Scope to find acceptable uom's for an so_line<commit_after>module Skr

    class Uom < Skr::Model

        belongs_to :sku, :inverse_of=>:uoms

        validates :price,  :numericality=>true, :allow_nil=>false
        validates :sku,    :presence=>true, :on=>:update
        validates :code,   :presence=>true
        validates :size,   :numericality => true, :length=>{:minimum=>1}
        validates :weight, :height, :width, :depth, :numericality=>{:greater_than=>0.1}, :allow_nil=>true

        export_methods :combined_uom, mandatory: true

        def combined_uom
            if self.size.nil? || self.code.nil?
                ''
            elsif 1 == self.size
                self.code
            else
                "#{self.code}/#{self.size}"
            end
        end

        def has_dimensions?
            ! self.dimensions.include?(nil)
        end

        def dimensions
            [ width, height, depth ]
        end

        def volume
            if has_dimensions?
                dimensions.inject(:*)
            else
                nil
            end
        end

        def blank?
            self.code.blank? || self.size.to_i == 0
        end


        def self.ea
            Uom.new({ :code=>'EA',:size=>1, :price=>0.0 })
        end

        export_scope :for_sku_loc, lambda{ | sku_loc_id = nil |
            if sku_loc_id
                Skr::Uom.joins(sku: [:sku_locs]).where(Skr::SkuLoc.table_name => {id: sku_loc_id})
            else
                Skr::Uom.none
            end
        }
    end


end # Skr module


__END__

        def for_public(user=nil,options={})
            as_json({
                :only=>%w{ code size base_price },
                :methods=>%w{ combined_uom dimensions volume }
            })
        end
{'fraction_non_alphanumeric': 0.11413708690330478, 'fraction_numerical': 0.004895960832313341, 'mean_word_length': 1.4897182025894897, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5177961', 'n_tokens_mistral': 1026, 'n_tokens_neox': 978, 'n_words': 212}