|
@@ -1,9 +1,14 @@
|
|
|
|
|
|
|
|
|
import yaml
|
|
|
+import yaml.representer
|
|
|
import datetime
|
|
|
|
|
|
-class Figure(object):
|
|
|
+yaml.Dumper.add_representer(unicode, yaml.representer.SafeRepresenter.represent_unicode)
|
|
|
+
|
|
|
+class Figure(yaml.YAMLObject):
|
|
|
+
|
|
|
+ yaml_tag = u"!figure"
|
|
|
|
|
|
def __init__(self, value, unit):
|
|
|
self.value = value
|
|
@@ -34,6 +39,22 @@ class Figure(object):
|
|
|
def __ne__(self, other):
|
|
|
return not (self == other)
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def from_yaml(cls, loader, node):
|
|
|
+ attr = loader.construct_mapping(node)
|
|
|
+ print(type(attr['unit']), attr['unit'])
|
|
|
+ return cls(
|
|
|
+ value = attr['value'],
|
|
|
+ unit = unicode(attr['unit']),
|
|
|
+ )
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def to_yaml(cls, dumper, figure):
|
|
|
+ return dumper.represent_mapping(
|
|
|
+ cls.yaml_tag,
|
|
|
+ {'unit': figure.get_unit(), 'value': figure.get_value()},
|
|
|
+ )
|
|
|
+
|
|
|
class Distance(Figure):
|
|
|
|
|
|
def __init__(self, value, unit):
|