//var Color = require('./Color')
import Color from './Color'

var hexRegex = /[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/

export default class Hex extends Color {
  
  constructor(str = '') {
    super()
    if (!Hex.isValid(str)) {
      throw "not a valid hex value"
    }
    this.value = this._stringToHex(str)
  }
  
  _expandShortHex(shortHex) {
    return shortHex.split('').map((v) => {return v+v}).join('')
  }
  
  _stringToHex(str) {
    let hex = hexRegex.exec(str)[0]
    hex = hex.length === 3 ? this._expandShortHex(hex) : hex
    return hex
  }
  
  static isValid(str) {
    return hexRegex.test(str)
  }
  
  toRgb() {
    let hex = this.value.match(/.{1,2}/g)
    return hex.map(function (v) {
        return parseInt(v, 16)
    })
  }
  
  toHsl() {
    
  }
  
  toString() {
    return this.value
  }
  
}

@@ -1,26 +1,22 @@
-//var
+import
  Color 
-= require(
+from 
 './C
@@ -24,17 +24,16 @@
 lor'
-)
 %0Aimport 
 Colo
@@ -24,29 +24,27 @@
 lor'%0Aimport 
-Color
+RGB
  from './Col
@@ -40,21 +40,19 @@
 from './
-Color
+RGB
 '%0A%0Avar h
@@ -651,30 +651,33 @@
 1,2%7D/g)%0A    
-return
+let rgb =
  hex.map(fun
@@ -726,16 +726,40 @@
 %0A    %7D)%0A
+    return new RGB(rgb)%0A
   %7D%0A  %0A 

return new RGB object in Hex.toRGB()