require 'boxcar/helpers'

module Boxcar
  module Smart
    def temperature
      raw_temp = `smartctl -d ata -A  /dev/#{device} | grep -i temperature`
      temp = raw_temp.match(/(\d+)(?:.?\(Min\/Max.+\))?$/)
      temp[1] if temp
    end

    def device_model
      info['Device Model']
    end

    def serial_number
      info['Serial Number']
    end

    def info
      return {} unless Boxcar::Helpers.unraid?
      @info ||= parse_smart_info
    end

  private

    def parse_smart_info
      raw_info = `smartctl -i /dev/#{device}`
      refined_info = raw_info.scan(/(^[\w\s]+):\s+(.+$)/)
      Hash[*refined_info.flatten]
    end
  end
end

require 'boxcar/helpers'

module Boxcar
  module Smart
    def temperature
      raw_value device, 'Temperature_Celsius'
    end

    def device_model
      info['Device Model']
    end

    def serial_number
      info['Serial Number']
    end

    def info
      return {} unless Boxcar::Helpers.unraid?
      @info ||= device_information
    end

  private

    def raw_value(device, param)
      `smartctl -d ata -A /dev/#{device} | grep #{param} | awk '{ print $10; }' 2>/dev/null`
    end

    def device_information
      raw_info = `smartctl -i /dev/#{device}`
      refined_info = raw_info.scan(/(^[\w\s]+):\s+(.+$)/)
      Hash[*refined_info.flatten]
    end
  end
end

Refactor reading values from SMART
Refactor reading values from SMART
